I am working on a c# compiler for the DynamicMethod so I try a lot of
strange things out. I came across this one:
public void CompileBug()
{
object obj = null + new object();
Console.WriteLine(obj.GetType().ToString() );
}
// IL disasm
{
// Method begins at RVA 0x111bc
// Code size 31 (0x1f)
.maxstack 2
.locals init ([0] object obj)
IL_0000: /* 00 | */ nop
IL_0001: /* 14 | */ ldnull
IL_0002: /* 73 | (0A)000024 */ newobj instance void
[mscorlib]System.Object::.ctor()
IL_0007: /* 28 | (0A)0001D0 */ call string
[mscorlib]System.String::Concat(object,
object)
IL_000c: /* 0A | */ stloc.0
IL_000d: /* 06 | */ ldloc.0
IL_000e: /* 6F | (0A)0000B4 */ callvirt instance class
[mscorlib]System.Type [mscorlib]System.Object::GetType()
IL_0013: /* 6F | (0A)00006E */ callvirt instance string
[mscorlib]System.Object::ToString()
IL_0018: /* 28 | (0A)000028 */ call void
[mscorlib]System.Console::WriteLine(string)
IL_001d: /* 00 | */ nop
IL_001e: /* 2A | */ ret
} // end of method XXX::CompileBug
I assume this should not compile at all. If I am right in my assumption
what should the error message be ? Something like "No implicit conversion
for ..." .
Is a literal null with no context considered to be of type Object (I thought
I saw that in ECMA 334).