Thread overview
[Issue 2030] New: String mixin within teplatate mixin doesn't compile
Apr 24, 2008
d-bugmail
Apr 24, 2008
d-bugmail
Apr 25, 2008
Janice Caron
Apr 25, 2008
d-bugmail
April 24, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2030

           Summary: String mixin within teplatate mixin doesn't compile
           Product: D
           Version: 2.013
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: bartosz@relisoft.com


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");


-- 

April 24, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2030


ary@esperanto.org.ar changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from ary@esperanto.org.ar  2008-04-24 17:30 -------
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");


-- 

April 25, 2008
On 24/04/2008, d-bugmail@puremagic.com <d-bugmail@puremagic.com> wrote:
>  mixin (foo !("hello"));

Shouldn't that be

    mixin foo!("hello");

i.e. without the extra pair of parentheses?
April 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2030





------- Comment #3 from bartosz@relisoft.com  2008-04-25 13:16 -------
Yes, it's a parentheses problem. Shows you that making two completely different constructs in a language differ only be parentheses is confusing.


--