Bug 10663 – Mixin int not converting

Status
RESOLVED
Resolution
INVALID
Severity
trivial
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-07-17T17:10:00Z
Last change time
2013-07-17T18:24:41Z
Assigned to
nobody
Creator
alienballance

Comments

Comment #0 by alienballance — 2013-07-17T17:10:51Z
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 by alienballance — 2013-07-17T17:12:05Z
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 by k.hara.pg — 2013-07-17T18:24:41Z
(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.