June 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10413

           Summary: .init incorrectly accepts any expression
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: clugdbug@yahoo.com.au


--- Comment #0 from Don <clugdbug@yahoo.com.au> 2013-06-19 03:04:04 PDT ---
According to the spec, only variables, fields, and types support the .init property. But all kinds of other things compile:

int foo() { return 1; }

static assert(foo.init == 0);

This gets changed into typeof(foo()).init.

---
diff --git a/src/mtype.c b/src/mtype.c
index 1c83eb9..8217e8d 100644
--- a/src/mtype.c
+++ b/src/mtype.c
@@ -2051,6 +2051,11 @@ Expression *Type::dotExp(Scope *sc, Expression *e,
Identifier *ident, int flag)
         char *s = e->toChars();
         e = new StringExp(e->loc, s, strlen(s), 'c');
     }
+    else if (ident == Id::init && ex->op != TOKtype)
+    {
+        error(e->loc, ".init can only be applied to variables, fields, and
types. Did you mean typeof(%s).init ?", e->toChars());
+        e = new ErrorExp();
+    }
     else
         e = getProperty(e->loc, ident, flag);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 26, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10413



--- Comment #1 from Don <clugdbug@yahoo.com.au> 2013-06-25 23:57:58 PDT ---
Pull request: https://github.com/D-Programming-Language/dmd/pull/2240

This fails Phobos unit tests in multiple places, for example:

std/traits.d(3654): Error: static assert  (is(void == double)) is false

With constructions like:
template Foo(T...)

     T[0].init
is OK if T[0] is a type, but if it is a value, it won't compile.
It is in fact pretty bizarre that 2.init == 0, so this should probably be
changed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------