Closed scabug closed 13 years ago
Imported From: https://issues.scala-lang.org/browse/SI-312?orig=1 Reporter: @mcdirmid
@dragos said: There is support for that already. The uncurry phase is lifting try-catches to methods when there are values on the stack /before/ entering the try-catch. An exception inside the try-catch would clean the stack, including any values pushed on the stack before the block.
The only thing that needs to be done is relax the condition under which this lifting is performed.
Sebastian Hack (shack) said: Fixed in r13762.
Try expressions that return a value are now generally transformed to store the resulting value in a local variable.
@odersky said: Milestone 2.7.0 deleted
Scala code:
Generated MSIL:
Output from PEVerify:
From the spec CLR architecture spec says in section 9.5, bullet point (4.b):
leave from the body of a try or catch (in this case the destination of the leave must have an empty evaluation stack and the leave instruction has the side-effect of emptying the evaluation stack).
To fix this, we must save the result from the stack in a local variable, then reload when the ret is made:
Correct MSIL:
I guess this means we have to get icode to stop leaving things on the stack....