In compiled code, return within an ensured section of code prevents ensure from
running
---------------------------------------------------------------------------------------
Key: JRUBY-1340
URL: http://jira.codehaus.org/browse/JRUBY-1340
Project: JRuby
Issue Type: Bug
Components: Compiler
Reporter: Charles Oliver Nutter
Fix For: JRuby 1.1.0
Ensure compilation is by means of Java try/finally. Return from within a method
is by means of a Java areturn opcode. Unfortunately, normal setup for a
"finally" in Java does not take returns into consideration. When compiling Java
code, javac must detect a return within a "try" and appropriately inline the
finally code to ensure it happens.
Currently in JRuby, the ensure logic does not do this. It installs a
try/finally, but does not inline "finally" logic (or install appropriate jumps)
into all jump locations that might leave the "try" section. This causes
compiled "return" to skip the "ensure" block that might be associated with it.
{noformat}
def foo
return
ensure
# this will never run
end
{noformat}
This also causes issues with test/unit, where assertions are added in an
ensured section of code:
{noformat}
def _wrap_assertion
@_assertion_wrapped ||= false
unless (@_assertion_wrapped)
@_assertion_wrapped = true
begin
add_assertion
return yield
ensure
@_assertion_wrapped = false
end
else
return yield
end
end
{noformat}
Because the ensure doesn't run, the @_assertion_wrapped ivar never gets
cleared, and assertions stop recording.
I will commit a temporary fix for this that forces method returns to use a
ReturnJump when within an ensured block, but the correct way to fix it is to
properly compile the try/finally for branching logic that would leave the "try"
section.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email