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

TryCatch and the Goto outside problems #442

Closed
dadhi opened this issue Dec 13, 2024 · 0 comments
Closed

TryCatch and the Goto outside problems #442

dadhi opened this issue Dec 13, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@dadhi
Copy link
Owner

dadhi commented Dec 13, 2024

See #438 for the context

When the last statement in a TryCatch block is a goto and the label is on the outside, we encounter an System.InvalidProgramException: Common Language Runtime detected an invalid program. error. We haven’t been able to find a reliable workaround for this yet.

// FEC throws `System.InvalidProgramException: Common Language Runtime detected an invalid program.`
var label = Label( "label" );
var variable = Variable( typeof( int ), "variable" );

var block = Block(
    [variable],
    TryCatch(
        Block(
            Assign( variable, Constant( 5 ) ),
            Goto( label )
        ),
        Catch(
            typeof( Exception ),
            Block(
                typeof( void ),
                Assign( variable, Constant( 10 ) )
            )
        )
    ),
    Label( label ),
    variable
);

var lambda = Lambda<Func<int>>( block );

Additionally we also found that when the label is moved into the same scope as the goto we get System.ArgumentException: Bad label content in ILGenerator.

// FEC throws `System.ArgumentException: Bad label content in ILGenerator.`
var label = Label( "label" );
var variable = Parameter( typeof( int ) );
var exceptionParam = Parameter( typeof( Exception ), "ex" );

var block = Block(
    [variable],
    TryCatch(
        Block(
            Goto( label ),
            Throw( Constant( new Exception( "Exception" ) ) ),
            Label( label ),
            Assign( variable, Constant( 2 ) )
        ),
        Catch( exceptionParam, Assign( variable, Constant( 50 ) ) )
    ),
    variable
);

var lambda = Lambda<Func<int>>( block );
var compiledLambda = lambda.CompileFast();
@dadhi dadhi self-assigned this Dec 13, 2024
@dadhi dadhi added the bug label Dec 13, 2024
@dadhi dadhi added this to the v5.0.1 milestone Dec 13, 2024
@dadhi dadhi changed the title TryCatch and Goto TryCatch and Goto problems Dec 13, 2024
@dadhi dadhi changed the title TryCatch and Goto problems TryCatch and the Goto outside problems Dec 13, 2024
dadhi added a commit that referenced this issue Dec 13, 2024
dadhi added a commit that referenced this issue Dec 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@dadhi dadhi closed this as completed in ba98371 Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant