Skip to content

Commit

Permalink
CLJ-1184: Don't compile [do ...] or #{do ...}
Browse files Browse the repository at this point in the history
The compiler should only treat do as a special form when it is
in the call position of an ISeq, not a vector or set.

Signed-off-by: Stuart Halloway <[email protected]>
  • Loading branch information
gfredericks authored and stuarthalloway committed Oct 25, 2013
1 parent bfe7409 commit 916da19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/jvm/clojure/lang/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6603,7 +6603,7 @@ public static Object eval(Object form, boolean freshLoader) {
try
{
form = macroexpand(form);
if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO))
if(form instanceof ISeq && Util.equals(RT.first(form), DO))
{
ISeq s = RT.next(form);
for(; RT.next(s) != null; s = RT.next(s))
Expand Down Expand Up @@ -7138,7 +7138,7 @@ static void compile1(GeneratorAdapter gen, ObjExpr objx, Object form) {
try
{
form = macroexpand(form);
if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO))
if(form instanceof ISeq && Util.equals(RT.first(form), DO))
{
for(ISeq s = RT.next(form); s != null; s = RT.next(s))
{
Expand Down
24 changes: 24 additions & 0 deletions test/clojure/test_clojure/compilation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,27 @@
(doseq [f (.listFiles (java.io.File. "test"))
:when (re-find #"dummy.clj" (str f))]
(.delete f)))))

(deftest CLJ-1184-do-in-non-list-test
(testing "do in a vector throws an exception"
(is (thrown? Compiler$CompilerException
(eval '[do 1 2 3]))))
(testing "do in a set throws an exception"
(is (thrown? Compiler$CompilerException
(eval '#{do}))))

;; compile uses a separate code path so we have to call it directly
;; to test it
(letfn [(compile [s]
(spit "test/clojure/bad_def_test.clj" (str "(ns clojure.bad-def-test)\n" s))
(try
(binding [*compile-path* "test"]
(clojure.core/compile 'clojure.bad-def-test))
(finally
(doseq [f (.listFiles (java.io.File. "test/clojure"))
:when (re-find #"bad_def_test" (str f))]
(.delete f)))))]
(testing "do in a vector throws an exception in compilation"
(is (thrown? Compiler$CompilerException (compile "[do 1 2 3]"))))
(testing "do in a set throws an exception in compilation"
(is (thrown? Compiler$CompilerException (compile "#{do}"))))))

0 comments on commit 916da19

Please sign in to comment.