[Issue 8718] New: Template mixin + string mixin name collision
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 23 23:46:53 PDT 2012
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 at puremagic.com
ReportedBy: monarchdodra at gmail.com
--- Comment #0 from monarchdodra at gmail.com 2012-09-23 23:47:48 PDT ---
>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: -------
More information about the Digitalmars-d-bugs
mailing list