icsharpcode/ILSpy — Issue #290: Exception:Cast from Int64 to Boolean not supported.
Author: aspark
Created: 2011-11-14 03:41:03+00:00
State: open

when parse the following il, ilspy will throw the exception:

IL_0009: nop
IL_000a: ldc.i4.1
IL_000b: ldc.i4.1
IL_000c: ceq
IL_000e: switch (IL_001f, IL_0020, IL_001f)

this il is obfuscated by tools.

can you change the way to determine the boolean type (MakePrimitive method in AstBuilder.cs)?

after changed like the following:

if (TypeAnalysis.IsBoolean(type) && val == 1)
return new Ast.PrimitiveExpression(true);
else if (TypeAnalysis.IsBoolean(type) && val != 1)
return new Ast.PrimitiveExpression(false);

the decompiled result is:

switch (1 == 1)
{
case false:
case false:
{
IL_1F:
break;
}
case true:
{
goto IL_20;
}
}