www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8718] New: Template mixin + string mixin name collision

http://d.puremagic.com/issues/show_bug.cgi?id=8718

           Summary: Template mixin + string mixin name collision
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com



From the (simplified) discussion  
http://forum.dlang.org/thread/xmoqikjmwfhqmuuncgiu forum.dlang.org

----
mixin template T(string s)
{
   void f()
   {
       mixin("++" ~ s ~ ";"); //L5
   }
}

struct S
{
   int x;
}

void main() {
   S a;
   S s;
   mixin T!("a.x");
   mixin T!("s.x"); //L18
}
----
main.d(5): Error: undefined identifier 'x', did you mean 'struct S'?
main.d(18): Error: mixin main.main.T!("s.x") error instantiating
----

When trying to instantiate the template mixin T the second time with "s.x", the
compiler gets confused because the name of the string parameter is also "s",
making "s.x" illegal.

I think this is a catch 22:

- On the one hand, the code generated by the template is, AFAIK, genuinely
illegal, as s shadows the outside world's s, and the generated "s.x" is indeed
illegal.

- On the other hand, I think it is not conceivable to tell a client "your code
failed to work, because you declared your variable with the same name as the
argument of a function: You are not allowed to call your variable s because
it's taken." WHAT?

Not sure what to make of this...

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