Bug 1241 – ICE on template instance parameter

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-05-18T17:22:00Z
Last change time
2014-02-16T15:25:24Z
Keywords
ice-on-valid-code
Assigned to
bugzilla
Creator
manuelk89

Comments

Comment #0 by manuelk89 — 2007-05-18T17:22:22Z
The following template instance parameter crashes dmd when the parameter gets accessed: template List(L...) { alias L get; } template Foo(alias A) { int len1 = A.get.length; // access causes ICE } void main() { alias Foo!(List!(1,2,3)) foo; // instance parameter is List!(1,2,3) } ------------------------------- compile session: $ dmd main.d dmd: expression.c:4729: virtual Expression* DotIdExp::semantic(Scope*): Assertion `0' failed. Aborted (core dumped) --- PS: when this gets fixed there is a nice way to pass more than one Tuple to a template by just passing several template instances that carry the tuples in them (just as the List template above).
Comment #1 by onlystupidspamhere — 2007-06-23T15:10:41Z
*** This bug has been marked as a duplicate of 911 ***
Comment #2 by shro8822 — 2007-07-22T12:02:40Z
I have also run into this one. I was trying to use the tuples+templates as compile time trees template Foo(A...) { template Bar(B...) { alias A a; alias B b; } } alias Foo!(Foo!(1,2,3).Bar!(4,5,6)).Bar!(Foo!(7,8,9).Bar!(10,11,12)) tree; foreach( a; tree.a) { foreach(aa; a.a); foreach(ab; a.b); } foreach( b; tree.b) { foreach(ba; b.a); foreach(bb; b.b); } Can we please get a fix on this one? It will drop a LOT of barriers to elaborate template systems. I have a few really cool things that use it and would like to put them in my talk without the disclaimer of "this would work but for bug #1241"
Comment #3 by manuelk89 — 2007-08-01T05:51:03Z
[email protected] wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=1241 > > > [email protected] changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > CC| |[email protected] > > > > > ------- Comment #2 from [email protected] 2007-07-22 12:02 ------- > I have also run into this one. I was trying to use the tuples+templates as > compile time trees > > template Foo(A...) > { > template Bar(B...) > { > alias A a; > alias B b; > } > } > > alias Foo!(Foo!(1,2,3).Bar!(4,5,6)).Bar!(Foo!(7,8,9).Bar!(10,11,12)) tree; > > foreach( a; tree.a) > { > foreach(aa; a.a); > foreach(ab; a.b); > } > foreach( b; tree.b) > { > foreach(ba; b.a); > foreach(bb; b.b); > } > > Can we please get a fix on this one? It will drop a LOT of barriers to > elaborate template systems. I have a few really cool things that use it and > would like to put them in my talk without the disclaimer of "this would work > but for bug #1241" > > I just discovered a decent workaround. Instead of using templates with tuple members, just use structs: Use struct Tuple(T...) { alias T tp; } instead of template Tuple(T...) { alias T tp; } I tested this with dmd1.020 and rewrote your tree structure using this trick: import std.stdio; struct Foo(A...) { struct Bar(B...) { alias A a; alias B b; } } alias Foo!(Foo!(1,2,3).Bar!(4,5,6)).Bar!(Foo!(7,8,9).Bar!(10,11,12)) tree; void main() { foreach( a; tree.a) { foreach(aa; a.a) writefln(aa); foreach(ab; a.b) writefln(ab); } foreach( b; tree.b) { foreach(ba; b.a) writefln(ba); foreach(bb; b.b) writefln(bb); } } This prints 1 2 3 4 5 6 7 8 9 10 11 12 for me. Happy coding!