Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested try/finally blocks only execute inner most finally block #786

Open
devhawk opened this issue Jun 21, 2023 · 2 comments
Open

Nested try/finally blocks only execute inner most finally block #786

devhawk opened this issue Jun 21, 2023 · 2 comments

Comments

@devhawk
Copy link
Contributor

devhawk commented Jun 21, 2023

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
@devhawk
Copy link
Contributor Author

devhawk commented Jun 21, 2023

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.

@devhawk
Copy link
Contributor Author

devhawk commented Jun 22, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant