Bug 2030 – String mixin within teplatate mixin doesn't compile

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-04-24T17:16:00Z
Last change time
2015-06-09T01:19:24Z
Assigned to
bugzilla
Creator
bartosz

Comments

Comment #0 by bartosz — 2008-04-24T17:16:35Z
The following code doesn't compile: template foo (string init) { mixin ("string str = \"" ~ init ~ "\";"); } mixin (foo !("hello")); attribute argument to mixin must be a string, not (foo!("hello")) Analogous code without a string mixin works: template bar (string s) { string str = s; } mixin bar!("hello");
Comment #1 by ary — 2008-04-24T17:30:45Z
No, the analogous code is template bar (string s) { string str = s; } mixin (bar!("hello")); and it doesn't compile (and it shouldn't). Notice the parenthesis after mixin. There's a difference between mixin something; and mixin (something); The first one is a template mixin (http://digitalmars.com/d/1.0/template-mixin.html), the second one is a mixin (http://www.digitalmars.com/d/1.0/mixin.html). This compiles correctly: template bar (string s) { string str = s; } mixin bar!("hello");
Comment #2 by caron800 — 2008-04-25T01:06:09Z
On 24/04/2008, [email protected] <[email protected]> wrote: > mixin (foo !("hello")); Shouldn't that be mixin foo!("hello"); i.e. without the extra pair of parentheses?
Comment #3 by bartosz — 2008-04-25T13:16:33Z
Yes, it's a parentheses problem. Shows you that making two completely different constructs in a language differ only be parentheses is confusing.