D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10663 - Mixin int not converting
Summary: Mixin int not converting
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 trivial
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-17 17:10 UTC by Mariusz Gliwiński
Modified: 2013-07-17 18:24 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mariusz Gliwiński 2013-07-17 17:10:51 UTC
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]
Comment 1 Mariusz Gliwiński 2013-07-17 17:12:05 UTC
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
Comment 2 Kenji Hara 2013-07-17 18:24:41 UTC
(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.