7694 – Internal error: e2ir.c 1251 when calling member function inside struct via alias param

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7694 - Internal error: e2ir.c 1251 when calling member function inside struct via alias param
Summary: Internal error: e2ir.c 1251 when calling member function inside struct via al...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: ice, pull
Depends on:
Blocks:
Reported: 2012年03月12日 12:42 UTC by Dmitry Olshansky
Modified: 2012年03月28日 22:51 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Dmitry Olshansky 2012年03月12日 12:42:51 UTC
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 Dmitry Olshansky 2012年03月22日 12:34:05 UTC
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.
Comment 2 Kenji Hara 2012年03月23日 22:38:49 UTC
https://github.com/D-Programming-Language/dmd/pull/827 
Comment 3 Kenji Hara 2012年03月23日 22:50:19 UTC
(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 Dmitry Olshansky 2012年03月24日 14:28:17 UTC
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 github-bugzilla 2012年03月28日 20:02:46 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/f8d472fed64a174472832d919f65b811fca0a968
Merge pull request #827 from 9rnsr/fix7694
Issue 7694 - Internal error: e2ir.c 1251 when calling member function inside struct via alias param


AltStyle によって変換されたページ (->オリジナル) /