Skip to content

Commit 916da19

Browse files
gfredericksstuarthalloway
authored andcommitted
CLJ-1184: Don't compile [do ...] or #{do ...}
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]>
1 parent bfe7409 commit 916da19

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/jvm/clojure/lang/Compiler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6603,7 +6603,7 @@ public static Object eval(Object form, boolean freshLoader) {
66036603
try
66046604
{
66056605
form = macroexpand(form);
6606-
if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO))
6606+
if(form instanceof ISeq && Util.equals(RT.first(form), DO))
66076607
{
66086608
ISeq s = RT.next(form);
66096609
for(; RT.next(s) != null; s = RT.next(s))
@@ -7138,7 +7138,7 @@ static void compile1(GeneratorAdapter gen, ObjExpr objx, Object form) {
71387138
try
71397139
{
71407140
form = macroexpand(form);
7141-
if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO))
7141+
if(form instanceof ISeq && Util.equals(RT.first(form), DO))
71427142
{
71437143
for(ISeq s = RT.next(form); s != null; s = RT.next(s))
71447144
{

test/clojure/test_clojure/compilation.clj

+24
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,27 @@
199199
(doseq [f (.listFiles (java.io.File. "test"))
200200
:when (re-find #"dummy.clj" (str f))]
201201
(.delete f)))))
202+
203+
(deftest CLJ-1184-do-in-non-list-test
204+
(testing "do in a vector throws an exception"
205+
(is (thrown? Compiler$CompilerException
206+
(eval '[do 1 2 3]))))
207+
(testing "do in a set throws an exception"
208+
(is (thrown? Compiler$CompilerException
209+
(eval '#{do}))))
210+
211+
;; compile uses a separate code path so we have to call it directly
212+
;; to test it
213+
(letfn [(compile [s]
214+
(spit "test/clojure/bad_def_test.clj" (str "(ns clojure.bad-def-test)\n" s))
215+
(try
216+
(binding [*compile-path* "test"]
217+
(clojure.core/compile 'clojure.bad-def-test))
218+
(finally
219+
(doseq [f (.listFiles (java.io.File. "test/clojure"))
220+
:when (re-find #"bad_def_test" (str f))]
221+
(.delete f)))))]
222+
(testing "do in a vector throws an exception in compilation"
223+
(is (thrown? Compiler$CompilerException (compile "[do 1 2 3]"))))
224+
(testing "do in a set throws an exception in compilation"
225+
(is (thrown? Compiler$CompilerException (compile "#{do}"))))))

0 commit comments

Comments
 (0)