Thread overview
[Issue 11954] New: Function call in string mixin inside mixin template without return value mistaken as declaration
Jan 20, 2014
Paul Freund
Jan 20, 2014
Andrej Mitrovic
Mar 07, 2014
Kenji Hara
January 20, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11954

           Summary: Function call in string mixin inside mixin template
                    without return value mistaken as declaration
           Product: D
           Version: D2
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: freund.paul@lvl3.org


--- Comment #0 from Paul Freund <freund.paul@lvl3.org> 2014-01-20 01:10:42 PST ---
Example code:

mixin template CallFkt() {
    mixin("testFkt();");
}

void testFkt() {
    import std.stdio : writeln;
    writeln("Called");
}

void main() {
    mixin CallFkt;
}

Output:

/d534/f170.d(2): Error: function declaration without return type. (Note that
constructors are always named 'this')
/d534/f170.d(2): Error: no identifier for declarator testFkt()
/d534/f170.d(11): Error: mixin f170.main.CallFkt!() error instantiating

Expected output:

Called

Description:

This code works when testFkt returns a value (int for example) and the call is
assigned to a variable (mixin("int i = testFkt();"); for example).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 20, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11954


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

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


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2014-01-20 10:38:10 PST ---
Mixin templates can only contain declarations, not statements.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 07, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11954



--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2014-03-07 01:28:02 PST ---
(In reply to comment #1)
> Mixin templates can only contain declarations, not statements.

To be more precise, mixin("testFkt();") is parsed as MixinDeclaraton:
http://dlang.org/module#MixinDeclaration

and it never be parsed as the MixinStatement: http://dlang.org/statement#MixinStatement

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