Clojure

Allow loops fully nested in catch/finally

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.5
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

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, compiling:(NO_SOURCE_PATH:1)
user=> (try (finally (loop [x 0] (if false (recur x)))))
CompilerException java.lang.UnsupportedOperationException: Cannot recur from catch/finally, compiling:(NO_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, compiling:(NO_SOURCE_PATH:3)
user=> (loop [x 0] (try (catch Exception e (recur x))))
CompilerException java.lang.UnsupportedOperationException: Can only recur from tail position, compiling:(NO_SOURCE_PATH:4)
user=> (loop [x 0] (try (finally (recur x))))
CompilerException java.lang.UnsupportedOperationException: Can only recur from tail position, compiling:(NO_SOURCE_PATH:5)

Activity

Hide
Andy Fingerhut added a comment -

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.

Show
Andy Fingerhut added a comment - 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.

People

Vote (4)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: