We're updating the issue view to help you get more done. 

Unfriendly Java cast expection when *compile-path* is set incorrectly

Description

When compile-path is not set to a String but to a java.io.File (that's what boot-clj does at the moment). You get a Cast exception in the compiler when trying to use it from the boot repl. Common wisdom seems to be to not compile from the repl, people say don't use gen-class. I find this unfortunate for when you do want to use gen-class and iterate quickly.

I haven't tested all older versions for this issue, but git blame shows that the code that should help here wasn't changed for 10 years:
https://github.com/clojure/clojure/blame/master/src/clj/clojure/core.clj#L6073
https://github.com/clojure/clojure/blame/master/src/jvm/clojure/lang/Compiler.java#L7643

My workaround now is:

1 2 3 4 5 6 7 8 9 (defn compile-safely [ns-name] (let [compile-path-class *compile-path* corrected-path (cond (instance? java.io.File compile-path-class) (.getAbsolutePath *compile-path*) (instance? String compile-path-class) *compile-path* :else (throw (ex-info "Unsupported class" {:class (class compile-path-class)})))] (binding [*compile-path* corrected-path] (compile ns-name))))

I suggest to put the type check in the 'clojure.core/compile function.

Environment

Mac OS, boot-clj

Status

Assignee

Unassigned

Reporter

Jeroen van Dijk

Labels

Approval

None

Patch

None

Affects versions

Release 1.8
Release 1.11
Release 1.10
Release 1.7
Release 1.9
Release 1.6

Priority

Minor