digitalmars.D.bugs - [Issue 4913] New: Repeated template instantiations with the same symbol argument fails
- d-bugmail puremagic.com (39/39) Sep 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4913
- d-bugmail puremagic.com (45/45) Sep 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4913
- d-bugmail puremagic.com (13/13) Feb 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=4913
http://d.puremagic.com/issues/show_bug.cgi?id=4913 Summary: Repeated template instantiations with the same symbol argument fails Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: rsinfu gmail.com --- The following valid code doesn't compile: -------------------- template Test(alias symbol) {} struct S(T...) { T vars; // (5) alias Test!(vars[0]) first; alias Test!(vars[0]) second; // (7) } alias S!(int) a; // (9) -------------------- % dmd -o- -c test.d test.d(5): Error: expression _vars_field_0 is not a valid template value argument test.d(7): Error: template instance test.Test!(_vars_field_0) error instantiating test.d(9): instantiated from here: S!(int) -------------------- The first instantiation of the Test with a symbol argument vars[0] succeeds. But the second instantiation fails. The error does not occur if the line (7) is commented out. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 21 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4913 Shin Fujishiro <rsinfu gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch --- This patch fixes the problem (dmd r680): ==================== --- src/template.c +++ src/template.c -4641,6 +4641,12 Identifier *TemplateInstance::genIdent() ea = NULL; goto Lsa; } + if (ea->op == TOKdsymbol) + { + sa = ((DsymbolExp *)ea)->s; + ea = NULL; + goto Lsa; + } buf.writeByte('V'); if (ea->op == TOKtuple) { ea->error("tuple is not a valid template value argument"); ==================== NOTE: I think the problem is that DsymbolExp::semantic() just returns 'this' if it already run, whereas the function does elaborate AST rewriting. As for this report's case, it rewrites itself to a VarExp *only* at the first semantic run. So, the following patch also fixes the reported problem. ==================== --- src/expression.c +++ src/expression.c -2244,8 +2244,10 Lagain: //printf("DsymbolExp:: %p '%s' is a symbol\n", this, toChars()); //printf("s = '%s', s->kind = '%s'\n", s->toChars(), s->kind()); +#if 0 if (type) return this; +#endif if (!s->isFuncDeclaration()) // functions are checked after overloading checkDeprecated(sc, s); s = s->toAlias(); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 21 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4913 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug yahoo.com.au Resolution| |FIXED Fixed https://github.com/D-Programming-Language/dmd/commit/69349699a8f770c6e06b440dfd1822c50826136a -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 06 2011