Thread overview
[Issue 1986] New: Mixin code from website doesn't compiler
Apr 11, 2008
d-bugmail
[Issue 1986] Mixin code from website doesn't compile
Apr 11, 2008
d-bugmail
Oct 25, 2008
d-bugmail
Dec 16, 2008
d-bugmail
Oct 25, 2011
Kasumi Hanazuki
Dec 02, 2012
Andrej Mitrovic
April 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1986

           Summary: Mixin code from website doesn't compiler
           Product: D
           Version: 2.012
          Platform: PC
               URL: http://www.digitalmars.com/d/2.0/mixin.html
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: bartosz@relisoft.com


This example from http://www.digitalmars.com/d/2.0/mixin.html doesn’t compile:

template GenStruct(char[] Name, char[] M1) {
    const char[] GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
}

mixin(GenStruct!("Foo", "bar"));


-- 

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


gide@nwawudu.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Mixin code from website     |Mixin code from website
                   |doesn't compiler            |doesn't compile




------- Comment #1 from gide@nwawudu.com  2008-04-11 13:08 -------
The corrected template doesn't compile,  it looks like string /invariant(char)[]/ prevents compilation, changing the type to 'invariant char[]' and everything is ok.

Also the error message doesn't have a line number, so there is probably two bugs occuring.

main.d
------
template GenStruct(string Name, string M1) {
    string GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
}

mixin(GenStruct!("Foo", "bar"));

C:\>dmd main.d
attribute argument to mixin must be a string, not (GenStruct)


-- 

October 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1986





------- Comment #2 from gide@nwawudu.com  2008-10-25 05:21 -------
This is working in DMD v2.020. The line number is in error message, but the message is still confusing because GenStruct *is* declared as a string, it should be declared as an 'invariant char [] GenStruct = ...'.

main.d
------
template GenStruct(string Name, string M1) {
    string GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
}

mixin(GenStruct!("Foo", "bar"));

main.d(5): Error: argument to mixin must be a string, not (GenStruct)


-- 

December 16, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1986


gide@nwawudu.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic




------- Comment #3 from gide@nwawudu.com  2008-12-16 10:08 -------
Added keyword diagnostic and simplified example, should error message should
say
"test.d(5): Error: argument to mixin must be a *invariant char[]* not
(*invariant(char)[]*)"?

test.d
------
invariant char[] str1 = "int x1;"; // OK
mixin(str1); // OK

string str2 = "int x2;";
mixin(str2); // Fails, test.d(5): Error: argument to mixin must be a string,
not (str2)


-- 

October 25, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=1986


Kasumi Hanazuki <k.hanazuki@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bitworld@qq.com


--- Comment #4 from Kasumi Hanazuki <k.hanazuki@gmail.com> 2011-10-25 08:21:35 PDT ---
*** Issue 6388 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=1986


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich@gmail.com
         Resolution|                            |FIXED


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-01 16:04:09 PST ---
> main.d(5): Error: argument to mixin must be a string, not (GenStruct)

is now:

> Error: variable GenStruct cannot be read at compile time

and

> Error: argument to mixin must be a string,
not (str2)

is:

> Error: variable str2 cannot be read at compile time

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------