EmitLiteral in Identifier.vb



if you have an expression accessing a value type field member and using the result in a further expression element which requires an address you run into an unhandled exception within the IL code, e.g.

Int32.MaxValue.ToString( )

MaxValue is a constant field of a value type and the ToString( ) will cause the exception in the IL code.

1.ToString( )

doesn't run into that problem, since the IL code generation is done in a different way (no field member).

How to fix that?
Change Identifier.vb in the following way

1) add a new parameter nextRequiresAddress As Boolean to Sub EmitLiteral like

Sub EmitLiteral(ByVal fi As System.Reflection.FieldInfo, ByVal ilg As FleeILGenerator, ByVal services As IServiceProvider, ByVal nextRequiresAddress As Boolean)

2) after code line elem.Emit(ilg, services) in Sub EmitLiteral add the following code

If nextRequiresAddress = True Then
EmitValueTypeLoadAddress(ilg, t)
End If

3) change the EmitFieldLoad Sub where the EmitLiteral Sub is called like

EmitLiteral(fi, ilg, services, Me.NextRequiresAddress)

Many thanks to the author of Flee for this excellent library!
best regards grabul