digitalmars.D.bugs - [Issue 5357] New: mixin templates accept strings as struct name
- d-bugmail puremagic.com (31/31) Dec 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (12/12) Dec 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (12/12) Dec 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (17/17) Dec 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (15/22) Dec 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (11/11) Dec 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (17/17) Dec 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
- d-bugmail puremagic.com (26/26) Dec 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5357
http://d.puremagic.com/issues/show_bug.cgi?id=5357
Summary: mixin templates accept strings as struct name
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: minor
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: gacek999 tlen.pl
---
Compiles on D2.050:
mixin template GenStruct1(string name)
{
struct name
{
}
}
mixin template GenStruct2(alias name)
{
struct name
{
}
}
mixin GenStruct1!("test");
mixin GenStruct2!("test2");
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
Jonathan M Davis <jmdavisProg gmx.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jmdavisProg gmx.com
PST ---
So, what's the problem? That seems perfectly okay to me. Templates generate
code. Here, you're generating code, and as part of that, you're giving the name
of the struct as a string. I don't see the problem.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
---
I forgot to add - try to use generated struct like this:
struct Other
{
test t;
}
Error: identifier 'test' is not defined
Error: test is used as a type
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
nfxjfg gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |nfxjfg gmail.com
Resolution| |INVALID
Dear god... stuff doesn't work this way AT ALL.
The name of the struct the mixin generates is "name", not whatever you passed
as the parameter named "name". What makes you think the compiler automatically
replaces identifier with the same name as the parameter by the parameter's
value?
Also, learn to write clear error reports.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
Piotr Szturmaj <gacek999 tlen.pl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |
---
Dear god... stuff doesn't work this way AT ALL.
Oh, really?
The name of the struct the mixin generates is "name", not whatever you passed
as the parameter named "name".
string name is a value parameter, so it should be an error. It should not
generate struct 'name'.
What makes you think the compiler automatically
replaces identifier with the same name as the parameter by the parameter's
value?
I don't think so! I was just experimenting with mixin templates.
Also, learn to write clear error reports.
You better learn how to reason.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
Piotr Szturmaj <gacek999 tlen.pl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |INVALID
---
I'm sorry. You're right.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
Lars T. Kyllingstad <bugzilla kyllingen.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugzilla kyllingen.net
00:37:40 PST ---
I think this is a bug after all. What does the symbol 'name' refer to inside
the template? The string or the struct? Here's a similar example, which quite
correctly fails to compile:
void foo(string bar)
{
struct bar { }
}
In this case, the compiler says "Error: declaration bar is already defined".
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 21 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5357
---
This is why I filled this bug report. I think it introduces a confusion,
Jonathan also got caught on that.
Consider following code:
mixin template Test(string s)
{
static string str = s;
//struct s { }
}
mixin Test!("text");
it compiles flawlessly. Now uncomment line with struct:
mixin template Test(string s)
{
static string str = s;
struct s { }
}
mixin Test!("text");
This time compiler fails with:
Error: cannot implicitly convert expression (s) of type s to string
Now it is impossible to refer to value parameter s. I think there should be at
least a warning which informs user that template declarations are hiding
template parameters.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 21 2010









d-bugmail puremagic.com 