Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class/forName considered as function name (proposal: say that it must be a simple symbol) #2277

Open
1 task done
arichiardi opened this issue Feb 12, 2024 · 8 comments
Open
1 task done
Projects

Comments

@arichiardi
Copy link

  • I have read the Clojure etiquette and will respect it when communicating on this platform.

version
2024.02.12

platform
linux - native binary

problem
I have the following in a file (for extending XTDB's handler):

(extend-protocol pedestal.servlet-interceptor/WriteableBody
           (Class/forName "[B") ;; This errors out
           (write-body-to-stream [^InputStream input-stream ^OutputStream output-stream]
             (with-open [out output-stream] (.write out ^bytes input-stream)))
           juxt.clojars_mirrors.muuntaja.v0v6v8.muuntaja.protocols.StreamableResponse
           (write-body-to-stream [^InputStream input-stream ^OutputStream output-stream]
             (with-open [out output-stream] ((.f input-stream) ^OutputStream out))))

The highlighter line is reported as:

src/web2/server.clj:53:27: error: Function name must be simple symbol but got: "[B"

I don't think it's a configuration error and it only happens with the latest version of clj-kondo.

expected behavior

It should not error out as above.

@borkdude
Copy link
Member

borkdude commented Feb 12, 2024

You can't officially use (Class/forName "[B") with extend-protocol.
Only class names are allowed, not expressions. That it works is accidental. In this case it's better to write the extend call manually. I can give links where this is discussed later on. One of the issues with doing what you do above is that it becomes unreliable when you have multiple expressions like that.

@arichiardi
Copy link
Author

I see, did not know that!

better to write the extend call or simply (?)

I'd like to know what "simply" is here cause I like simple :)

@borkdude
Copy link
Member

That was a typo. Writing extend is simple.

@borkdude
Copy link
Member

In Clojure 1.12 you will be able to write (extend-protocol IFoo byte* ...)

@borkdude
Copy link
Member

@borkdude
Copy link
Member

I think we could improve the error message to say that the class name must be a simple symbol

@borkdude borkdude changed the title Class/forName considered as function name Class/forName considered as function name (proposal: say that it must be a simple symbol) Feb 12, 2024
@borkdude borkdude added this to Needs triage in clj-kondo via automation Feb 12, 2024
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo Feb 12, 2024
@borkdude borkdude moved this from High priority (next release) to In progress in clj-kondo Feb 19, 2024
@borkdude
Copy link
Member

@borkdude
Copy link
Member

I'll leave this issue open until CLJ-2836 is resolved.

@borkdude borkdude moved this from In progress to Medium priority (new / enhance) in clj-kondo Feb 20, 2024
d-t-w added a commit to factorhouse/slipway that referenced this issue Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
clj-kondo
  
Medium priority (new / enhance)
Development

No branches or pull requests

2 participants