Thread overview
[Issue 10485] New: can not distinguish method call in string mixin!
Jun 27, 2013
changlon
Jun 27, 2013
changlon
Jun 27, 2013
Andrej Mitrovic
Jun 27, 2013
Andrej Mitrovic
Jun 28, 2013
changlon
June 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10485

           Summary: can not distinguish method call in string mixin!
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: changlon@gmail.com


--- Comment #0 from changlon <changlon@gmail.com> 2013-06-26 21:20:23 PDT ---
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
--------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10485



--- Comment #1 from changlon <changlon@gmail.com> 2013-06-26 21:23:41 PDT ---
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
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10485


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

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


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-27 06:49:54 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10485



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-27 06:50:57 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10485



--- Comment #4 from changlon <changlon@gmail.com> 2013-06-27 18:49:17 PDT ---
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.

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