Allow loops fully nested in catch/finally

Description

~/clj-git/clojure $ java -cp clojure.jar clojure.main
Clojure 1.3.0-alpha2-SNAPSHOT
user=> (try (catch Exception e (loop [x 0] (recur x))))
CompilerException java.lang.UnsupportedOperationException: Cannot recur from catch/finally, compilingNO_SOURCE_PATH:1)
user=> (try (finally (loop [x 0] (if false (recur x)))))
CompilerException java.lang.UnsupportedOperationException: Cannot recur from catch/finally, compilingNO_SOURCE_PATH:2)

With attached patch (should also fix CLJ-31):

~/clj-head/clojure $ java -cp clojure.jar clojure.main
Clojure 1.3.0-alpha2-SNAPSHOT
user=> (try (catch Exception e (loop [x 0] (recur x))))
nil
user=> (try (finally (loop [x 0] (if false (recur x)))))
nil
user=> (loop [x 0] (try (if false (recur x))))
CompilerException java.lang.UnsupportedOperationException: Can only recur from tail position, compilingNO_SOURCE_PATH:3)
user=> (loop [x 0] (try (catch Exception e (recur x))))
CompilerException java.lang.UnsupportedOperationException: Can only recur from tail position, compilingNO_SOURCE_PATH:4)
user=> (loop [x 0] (try (finally (recur x))))
CompilerException java.lang.UnsupportedOperationException: Can only recur from tail position, compilingNO_SOURCE_PATH:5)

Environment

None

Attachments

2
  • 25 Feb 2012, 12:47 AM
  • 31 Oct 2010, 06:51 PM

Activity

Show:

Andy Fingerhut February 25, 2012 at 12:47 AM

clj-667-allow-loop-recur-nested-in-catch-and-finally-patch2.txt applies cleanly to latest master as of Feb 24, 2012.

I cannot vouch for the changes in Compiler.java – I simply modified what was in Juha Arpiainen's patch so that they applied cleanly. Some of the context changed noticeably due to a patch for CLJ-31 by Kevin Downey that was applied.

The test parts of the patch I can vouch for. Some of the previously existing tests seem not to test what they should. I can make a separate patch with just the updated passing tests if that is desired.

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Fix versions

Created October 31, 2010 at 6:51 PM
Updated June 15, 2012 at 5:09 PM
Resolved June 15, 2012 at 5:09 PM