3

An example probably explains it best. Why does the 2nd and 3rd examples work?

Integer/MAX_VALUE
=> 2147483647
(Integer/MAX_VALUE)
=> 2147483647
((((((Integer/MAX_VALUE)))))) ; wtf?
=> 2147483647

(1) ; crashes as expected
Execution error (ClassCastException) at medino-web.handler/eval7997 (form-init17779606850549883231.clj:1).
class java.lang.Long cannot be cast to class clojure.lang.IFn (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')

1 Answer 1

6

From the source code of Clojure 1.12:

// Preserving the existing static field bug that replaces a reference in parens with
// the field itself rather than trying to invoke the value in the field. This is
// an exception to the uniform Class/member qualification per CLJ-2806 ticket.
if(fexpr instanceof StaticFieldExpr)
    return fexpr;

So it seems that that behavior is a bug that was deliberately not fixed to avoid breakage to any existing code that might be relying on it.

Sign up to request clarification or add additional context in comments.

2 Comments

I feel like in ye olde days, like back in 2010, it used to be pretty normal to write (Integer/MAX_VALUE). It's certainly been allowed since at least 1.0, so I think it's a bit silly for the author(s) to call it a "bug" when it's been left unfixed for 15 years, and never will be fixed because of backwards compatibility.
I don't think it's silly - it discourages using that syntax. And prior to CLJ-2806 it wasn't important at all, so I assume that's why it wasn't really labeled as a bug before. Similar to how clojure.set functions returning reasonable results for some combinations of non-set arguments is not labeled as a bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.