www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4913] New: Repeated template instantiations with the same symbol argument fails

reply d-bugmail puremagic.com writes:
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


--- Comment #0 from Shin Fujishiro <rsinfu gmail.com> 2010-09-21 18:41:06 PDT
---
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4913


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-09-21 18:43:39 PDT
---
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
prev sibling parent d-bugmail puremagic.com writes:
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


--- Comment #2 from Don <clugdbug yahoo.com.au> 2011-02-06 13:45:53 PST ---
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