Nested try/finally blocks only execute inner most finally block
ConvertReturnStatement pushes an ENDTRY operation instead of a JUMP if the return call is inside at least one try/finally block. This works fine if there is only a single try/finally block. If there are nested try/finally blocks, only the inner most finally block is executed. Any other finally blocks are skipped
Example contract Method:
public static void Test2()
{
try
{
Runtime.Log("outer try");
try
{
Runtime.Log("inner try");
return;
}
finally
{
Runtime.Log("inner finally");
}
}
finally
{
Runtime.Log("outer finally");
}
}
expected debug output:
Runtime.Log: SampleRegistrar outer try
Runtime.Log: SampleRegistrar inner try
Runtime.Log: SampleRegistrar inner finally
Runtime.Log: SampleRegistrar outer finally
actual debug output:
Runtime.Log: SampleRegistrar outer try
Runtime.Log: SampleRegistrar inner try
Runtime.Log: SampleRegistrar inner finally
In the TS devpack, I'm planning on emitting an endtry/noop pair for each nested try/catch block except the last one. For the last one, I'm going to emit the endtry to return target. Alternatively, we could emit an endtry/noop pair for each nested try/catch block and then add a JUMP to return target at the end.
In the TS devpack, I'm planning on emitting an endtry/noop pair for each nested try/catch block except the last one. For the last one, I'm going to emit the endtry to return target. Alternatively, we could emit an endtry/noop pair for each nested try/catch block and then add a JUMP to return target at the end.
Note, there's no need to emit a noop. In the TS compiler, I'm emitting an endtry for each nested try block. For each endtry except the last, I'm just targeting the next endtry. The final endtry targets the return target.