[Issue 10413] New: .init incorrectly accepts any expression
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 19 03:04:05 PDT 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 at puremagic.com
ReportedBy: clugdbug at yahoo.com.au
--- Comment #0 from Don <clugdbug at 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: -------
More information about the Digitalmars-d-bugs
mailing list