www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1986] New: Mixin code from website doesn't compiler

reply d-bugmail puremagic.com writes:
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"));


-- 
Apr 10 2008
next sibling parent d-bugmail puremagic.com writes:
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)


-- 
Apr 11 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
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)


-- 
Oct 25 2008
prev sibling parent d-bugmail puremagic.com writes:
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)


-- 
Dec 16 2008