-
-
Notifications
You must be signed in to change notification settings - Fork 91
Closed
Description
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();