-
-
Notifications
You must be signed in to change notification settings - Fork 91
Closed
Description
see #438 for the context
Single-Test Switch Without a Default Case
If a switch contains only one TestValue and no default case, we get an error during conditional generation. This seems to occur even when such a structure would otherwise be valid.
// FEC throws System.NullReferenceException: Object reference not set to an instance of an object.
var label = Label( "label" );
var block = Block(
Switch(
Constant( 1 ),
SwitchCase( Goto( label ), Constant( 1 ) ) // This gets emitted as a conditional with a null False block
),
Label( label ),
Constant( 2 )
);
var lambda = Lambda<Func<int>>( block );
var compiledLambda = lambda.CompileFast();
Switch Without Any Test Cases
If a switch contains zero test cases it throws System.ArgumentOutOfRangeException: Index was out of range.. In this case we optimized our code to avoid this scenario.
// FEC throws System.ArgumentOutOfRangeException: Index was out of range.
// WORKAROUND: Do not use empty cases
var block = Block(
Switch(
Constant( 1 ),
[] // empty cases (no body should do this)
),
Constant( 2 )
);
var lambda = Lambda<Func<int>>( block );
var compiledLambda = lambda.CompileFast();