Bug 11954 – Function call in string mixin inside mixin template without return value mistaken as declaration

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2014-01-20T01:10:00Z
Last change time
2014-03-07T01:28:02Z
Assigned to
nobody
Creator
freund.paul

Comments

Comment #0 by freund.paul — 2014-01-20T01:10:42Z
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).
Comment #1 by andrej.mitrovich — 2014-01-20T10:38:10Z
Mixin templates can only contain declarations, not statements.
Comment #2 by k.hara.pg — 2014-03-07T01:28:02Z
(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