Skip to content

Support unused Field access in Block #439

@dadhi

Description

@dadhi

see #438 for the context

When unused expressions are introduced in the expression tree, we encountered issues. We've resolved this by cleaning up our code to avoid adding these unnecessary snippets. (We didn't actually see these issues originally, so this help us clean up our code nicely!)

// FEC throws System.InvalidProgramException: Common Language Runtime detected an invalid program.
// WORKAROUND: Remove the unused value from the block

public class TestClass
{
    public int Result0 = 42;
    public int Result1;
}

var variable = Variable( typeof( TestClass ), "testClass" );

var block = Block(
    [variable],
    Assign(
        variable,
        New( typeof( TestClass ) )
    ),
    Block(
        Field( variable, nameof( TestClass.Result0 ) ), // Unused
        Assign(
            Field( variable, nameof( TestClass.Result1 ) ),
            Field( variable, nameof( TestClass.Result0 ) )
        )
    ),
    Field( variable, nameof( TestClass.Result1 ) )
);

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions