www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17992] New: auto return type and null for classes


          Issue ID: 17992
           Summary: auto return type and null for classes
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: temtaime gmail.com

class C
        int v;

        C parent;
        C[] childs;

        auto foo(int a)
                a -= v;

                if(parent && a < 0)
                        return null;

                foreach(c; childs)
                        if(auto r = c.foo(a))
                                pragma(msg, typeof(r));
                                return r;

                        return this;

                return null;

void main()
        auto a = new C, b = new C;

        a.v = 12;

        b.parent = a;
        a.childs ~= b;

        assert(a.foo(123) is b);

It passes, but prints typeof(null)
It should print C or give an error with pragma or doesn't compile at all.

LDC team says it's impossible to generate code from frontend data so this
example doesn't work with ldc.

Nov 18