Bug 10485 – can not distinguish method call in string mixin!
Status
RESOLVED
Resolution
INVALID
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2013-06-26T21:20:00Z
Last change time
2013-06-27T18:49:17Z
Assigned to
nobody
Creator
changlon
Comments
Comment #0 by changlon — 2013-06-26T21:20:23Z
code:
---------------
class TestClass{
void call(){
}
}
mixin template test(string name){
mixin("scope " ~ name ~ " = new TestClass;" );
mixin( name ~ ".call();" );
}
void main(){
mixin test!("var");
var.call();
}
---------------
error:
--------------
debug.d(10): Error: function declaration without return type. (Note that constructors are always named 'this')
debug.d(10): Error: no identifier for declarator var.call()
debug.d(10): Error: function debug.TestClass.call is used as a type
debug.d(14): Error: mixin debug.main.test!("var") error instantiating
--------------
Comment #1 by changlon — 2013-06-26T21:23:41Z
this seems is a different but related bug:
code:
----------------------
class TestClass{}
mixin template test(string name){
mixin("scope " ~ name ~ " = new TestClass;" );
}
void main(){
mixin test!("var");
}
---------------------
run error:
--------------------
object.Error: Illegal Instruction
----------------
0x0012FE30
0x00402BFC
0x00402C37
0x00402835
0x00402098
0x7C817067 in RegisterWaitForInputIdle
--------------------
Comment #2 by andrej.mitrovich — 2013-06-27T06:49:54Z
Templates can only be used to create declarations, not expressions. One workaround is to write the code like the following:
-----
import std.stdio;
class TestClass
{
void call()
{
writeln("called");
}
}
mixin template test(string name)
{
struct S
{
void call()
{
scope tc = new TestClass;
tc.call();
}
}
mixin("S " ~ name ~ ";");
}
void main(){
mixin test!("var");
var.call();
}
-----
But note that 'scope' is a feature that will eventually be deprecated.
Comment #3 by andrej.mitrovich — 2013-06-27T06:50:57Z
(In reply to comment #1)
> this seems is a different but related bug:
>
> code:
> ----------------------
> class TestClass{}
> mixin template test(string name){
> mixin("scope " ~ name ~ " = new TestClass;" );
> }
> void main(){
> mixin test!("var");
> }
> ---------------------
It seems to be a bug related to scope, if you change it to 'auto' it will work. You could file this as a separate bug, but since scope is guaranteed to go away soon in a future release chances are low that it will be fixed.
Comment #4 by changlon — 2013-06-27T18:49:17Z
Thanks for the quick response.
I will use that scope late, the struct wrapper will not work here.
I use this:
-----
string test(string name, alias T1)(){
string code = "scope " ~ name ~ " = new ubyte[ " ~ T1.stringof~ ".length + 1 ];\n" ;
code ~= data ~ "[$-1] = 0;\n" ;
return code ;
}
void main(strings args){
mixin( test!("var", args[0]) ) ;
capi_call(var.ptr);
}
----
I will create bug for scope mixin.