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.