Bug 7694 – Internal error: e2ir.c 1251 when calling member function inside struct via alias param
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-12T12:42:00Z
Last change time
2012-03-28T22:51:59Z
Keywords
ice, pull
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2012-03-12T12:42:51Z
As is the following gives assert on line 8 as expected,
uncomment bootstrap to get Internal error: e2ir.c 1251
template Instruction(int ir)
{
void match(alias s, alias m)(){ m.nextState(); }
}
struct T{
void nextState(){ assert(0); }
/* void bootstrap()
{
return Instruction!(0).match!(this, this)();
}*/
}
T t;
void main()
{
// t.bootstrap();
Instruction!(0).match!(t, t)();
}
on dmd 2.059head win7 x64
last commit: bcfd90aae05bd6259212ec870b2c037569029d77
Comment #1 by dmitry.olsh — 2012-03-22T12:34:05Z
Minimized test case and a workaround:
void match(alias m)(){
m.foo();//removing this line supresses ice in both cases
}
struct T{
void foo(){}
void bootstrap()
{
//next line causes ice
// match!(this)();
//while this works:
alias this p;
match!(p)();
}
}
void main(){}
Apaaerntly it has something to do with plain 'this' being mistreated in when passed as alias.
(In reply to comment #0)
> As is the following gives assert on line 8 as expected,
> uncomment bootstrap to get Internal error: e2ir.c 1251
>
> template Instruction(int ir)
> {
> void match(alias s, alias m)(){ m.nextState(); }
> }
>
>
> struct T{
> void nextState(){ assert(0); }
> /* void bootstrap()
> {
> return Instruction!(0).match!(this, this)();
> }*/
> }
>
> T t;
> void main()
> {
>
> // t.bootstrap();
> Instruction!(0).match!(t, t)();
> }
With my pull, this code doesn't report ice, but raises following errors:
test.d(11): Error: template instance match!(this,this) cannot use local 'this' as parameter to non-global template match(alias s,alias m)
test.d(11): Error: template instance match!(this,this) cannot use local 'this' as parameter to non-global template match(alias s,alias m)
But I think this is a little harsh error. The nested template (function) match in module template Instruction really needs only one context, that is enclosing 'this' given as alias parameters m and n.
Comment #4 by dmitry.olsh — 2012-03-24T14:28:17Z
I think the error is tolerable, when I found workaround I just rewrote it to global template. Less flexible maybe, but works for me.
Comment #5 by github-bugzilla — 2012-03-28T20:02:46Z