Summary: Template mixin + string mixin name collision
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2012-09-23 23:47:48 PDT ---
>From the (simplified) discussion @

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

- 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:
------- You are receiving this mail because: -------

Reply via email to