www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11954] New: Function call in string mixin inside mixin template without return value mistaken as declaration

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



---
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: -------
Jan 20 2014
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jan 20 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11954





 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: -------
Mar 07 2014