ClojureScript

ClojureScript macro eval bug since 0.0-1211?

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

As discussed on the Mailing List:

--------------------------------------------------------------

Hello ClojureScripters,

I'm trying to update a port of hiccup [1] to the latest
ClojureScript version. During HTML compilation I call at some
point eval (in a Clojure macro) on a datastructure and get a
java.lang.ClassCastException. This used to work in ClojureScript
versions before 0.0-1211.

I traced it down to the following example. This works in
ClojureScript 0.0-1011:

; Define a Clojure macro.
(defmacro eval-test [arg]
(eval arg))

; Use the Clojure macro from ClojureScript.
(eval-test "1")
;=> "1"
(eval-test 1)
;=> 1
(eval-test "div")
;=> "div"
(eval-test :div)
;=> :div
(eval-test [])
;=> []
(eval-test {})
;=> {}
(eval-test #{})
;=> #{}

In ClojureScript 0.0-1211 it works on strings, numbers and
symbols, but fails on vectors, maps and sets. I get the follwoing
results:

(eval-test "1")
;=> "1"
(eval-test 1)
;=> 1
(eval-test "div")
;=> "div"
(eval-test :div)
;=> :div
(eval-test [])

java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace, compiling:(NO_SOURCE_PATH:1)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6462)
at clojure.lang.Compiler.analyze(Compiler.java:6262)
at clojure.lang.Compiler.eval(Compiler.java:6508)
at clojure.lang.Compiler.eval(Compiler.java:6477)
at clojure.core$eval.invoke(core.clj:2797)
at hiccup.core$eval_test.invoke(core.clj:20)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:605)
at cljs.compiler$macroexpand_1.invoke(compiler.clj:1351)
at cljs.compiler$analyze_seq.invoke(compiler.clj:1368)
at cljs.compiler$analyze.invoke(compiler.clj:1425)
at cljs.compiler$analyze.invoke(compiler.clj:1418)
at cljs.repl$evaluate_form.invoke(repl.clj:64)
at cljs.repl$eval_and_print.invoke(repl.clj:124)
at cljs.repl$repl.doInvoke(repl.clj:173)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at cljsbuild.repl.listen$run_repl_listen.invoke(listen.clj:10)
at cljsbuild.repl.listen$run_repl_launch.invoke(listen.clj:31)
at user$eval2490.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6511)
at clojure.lang.Compiler.eval(Compiler.java:6500)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.eval(Compiler.java:6477)
at clojure.core$eval.invoke(core.clj:2797)
at clojure.main$eval_opt.invoke(main.clj:297)
at clojure.main$initialize.invoke(main.clj:316)
at clojure.main$null_opt.invoke(main.clj:349)
at clojure.main$main.doInvoke(main.clj:427)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:419)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)
Caused by: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace
at clojure.lang.Compiler.currentNS(Compiler.java:6864)
at clojure.lang.Compiler.lookupVar(Compiler.java:6826)
at clojure.lang.Compiler.lookupVar(Compiler.java:6847)
at clojure.lang.Compiler.isInline(Compiler.java:6323)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6448)
... 33 more
java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace, compiling:(NO_SOURCE_PATH:1)

Does anyone have an idea what has changed between those versions?
Could this be a bug?

Thanks for your help, Roman.

Activity

Hide
David Nolen added a comment -

Patch welcome. I suspect this may be due to us binding cljs-ns to ns in compiler.clj line 1450. This was done to give file & line numbers for macro errors.

Show
David Nolen added a comment - Patch welcome. I suspect this may be due to us binding cljs-ns to ns in compiler.clj line 1450. This was done to give file & line numbers for macro errors.
Hide
Brian Taylor added a comment -

macroexpand-1 is binding ns to a symbol but the Clojure compiler assumes ns will be a namespace. We find or create an appropriately named CLJ namespace for the parallel CLJS namespace being compiled.

Show
Brian Taylor added a comment - macroexpand-1 is binding ns to a symbol but the Clojure compiler assumes ns will be a namespace. We find or create an appropriately named CLJ namespace for the parallel CLJS namespace being compiled.
Hide
Brian Taylor added a comment -

This may also address CLJS-152 (though I suspect we'll need a test case or feedback from the ticket creator to be sure.)

Show
Brian Taylor added a comment - This may also address CLJS-152 (though I suspect we'll need a test case or feedback from the ticket creator to be sure.)
Hide
David Nolen added a comment -

fixed, 6eada144088a373fe5c2b1eed65d6d3a8d75cb37

Show
David Nolen added a comment - fixed, 6eada144088a373fe5c2b1eed65d6d3a8d75cb37
Hide
Roman Scherer added a comment -

I can confirm that this patch solved my problem. Thanks for fixing this so fast ...

Show
Roman Scherer added a comment - I can confirm that this patch solved my problem. Thanks for fixing this so fast ...

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: