Re: ms csharp compiler bug

Tech-Archive recommends: Speed Up your PC by fixing your registry



it looks strange but i'd consider it a valid expression and so it should
compile and even produce a result. Why do you think it is a bug?
Mathematically, an empty set plus an object must evaluate to the object
right?

However, when I run the example, I get a system.string being printed out
with the code. Removing the null, I get a system.object. That to me implies
an inconsistency.

thoughts/comments?
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


"Toby Altman" <TobyAltman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AE974BF3-6A1F-4B04-9284-36966D31E5AE@xxxxxxxxxxxxxxxx
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).



.



Relevant Pages

  • Re: DevExpress & D8
    ... > anyone) to support .NET. ... I know and I agree - it is somewhat strange. ... >> language? ... > solution so they could compile the same code and get both a managed ...
    (borland.public.delphi.non-technical)
  • Re: Version mismatch between kqemu module and qemu
    ... Now when I simply install qemu from a DVD and try to run the machine: ... It is strange to me that I have to compile a a package in order to get the ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Generic kernel compilation
    ... > It's strange that others were able to compile the generic kernel without ... I have read something about Athlon optimization ...
    (alt.os.linux.suse)
  • Re: The illusion of "portability"
    ... language. ... That's strange. ... I expect they would compile and execute successfully on any ... I am not telling you that portable programs do not exists or that ...
    (comp.lang.c)
  • Re: gcc inline cause performance drop drastically
    ... algorithm is a bit complex and due to some reason I can't paste the ... The strange thing is when I compile it with -O3, ...
    (comp.unix.programmer)