www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10663] New: Mixin int not converting

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10663

           Summary: Mixin int not converting
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: trivial
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: alienballance gmail.com


--- Comment #0 from Mariusz Gliwiński <alienballance gmail.com> 2013-07-17
17:10:51 PDT ---
I know i should minimise it more, but i'm too tired already. And dpaste just
stopped working :(

DMD v2.063.2

[CODE]
import std.conv;

struct StateRunning{}
struct StateDisposer{}

template Declaration(uint idx, T)
{
  enum Declaration =
       "const("~T.stringof~")* _s"~idx~";";
  //text("const(",T.stringof,")* _s",idx,";");                                  
}

template DeclarationMulti(T...)
{
  template Loop(string ret,size_t i,Args...)
  {
    static if( Args.length == 0 ) 
    {   
      enum Loop = ret;
    }   
    else
    {   
      enum Loop = Loop!(ret~Declaration!(i,Args[0])~"\n", i+1, Args[1..$]);
    }   
  }
  enum DeclarationMulti = Loop!("",0,T);
}
struct State(T...)
{
  mixin(DeclarationMulti!(T));
  void test(T args)
  {
    foreach( i, arg; args )
    {   
      mixin("_s"~to!string(i)) = &arg;
    }   
  }
}

void main(string[] args)
{
  StateRunning r;
  StateDisposer d;
  State!(StateRunning,StateDisposer) s;
  s.test(r,d);
}
[/CODE]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 17 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10663



--- Comment #1 from Mariusz Gliwiński <alienballance gmail.com> 2013-07-17
17:12:05 PDT ---
That's the error:
src/main.d(43): Error: semicolon expected, not 'EOF'
src/main.d(48): Error: undefined identifier _s0, did you mean variable _s?
src/main.d(48): Error: undefined identifier _s1, did you mean variable _s?
src/main.d(57): Error: template instance nawia.main.State!(StateRunning,
StateDisposer) error instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10663


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-07-17 18:24:41 PDT ---
(In reply to comment #0)
[snip]

Problem is in Declaration template.

 
 template Declaration(uint idx, T)
 {
   enum Declaration =
        "const("~T.stringof~")* _s"~idx~";";   // here
   //text("const(",T.stringof,")* _s",idx,";");                                
 
 }
It concatenates string ~ uint ~ string. When uint idx is 0, Declaration!(0, T) generates "const(StateRunning)* _s\0;" There's null character. Then, in mixin statement, dmd lexer extract null character as EOF token, and reports "semicolon expected, not 'EOF'" error. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 17 2013