Tech Off Post

Single Post Permalink

View Thread: null + null = ?
  • User profile image

    I think this is a ( minor )compiler bug. The self referencing constructors seem to have it pretty confused - it should probably throw a diagnostic here.

    It's somewhat of an edge case( you could never construct a class1 without a stack overflow ).

    What's happening is that the compiler is seeing that it can never construct one of these things so isn't rewriting the class to add the initializers to the constructor. So it sees

    public int c; // ( no = true )

    This doesn't just work for bools of course - this class gives the appearance of being a general "reinterpret_cast<> class Smiley" able to convert any type to any the following compiles fine also...

    class Class1
    public int c = true; // <---- It compiles!!
    public DateTime d = 10.243;
    public float f = "Rabbit";
    public Guid g = new DateTime( "10/10/2002 10:53Z" );
    public Class1(): this(0) {}
    public Class1(int i) : this() {}