digitalmars.D.bugs - bug(?) with recursive aliases
- Sean Kelly (74/74) Feb 09 2006 I'm not sure whether this is a bug, but I haven't been able to find a
- Sean Kelly (17/17) Feb 09 2006 I think I'm merely running up against the limitations of 'alias' here.
- Thomas Kuehne (12/28) Feb 11 2006 -----BEGIN PGP SIGNED MESSAGE-----
I'm not sure whether this is a bug, but I haven't been able to find a syntax that works. Notice that t.val!(0) is fine, so the problem is expanding "alias tail.val!(n-1) val": C:\code\d>type test.d void main() { auto t = new Tuple!(int,Tuple!(int))(); t.val!(0) = 1; t.val!(1) = 2; } struct Empty { } class Tuple( HeadType, TailType = Empty ) { alias HeadType Type; HeadType head; TailType tail; template val( int n ) { static if( n == 0 ) alias head val; else static if( is( typeof(tail) == Empty ) ) alias tail val; else alias tail.val!(n-1) val; } } C:\code\d>dmd test test.d(27): template identifier val is not a member of tail test.d(6): template instance test.Tuple!(int,Tuple).Tuple.val!(1) error instantiating test.d(6): cannot implicitly convert expression (2) of type int to test.Tuple!(int).Tuple C:\code\d> I also tried partial specialization, thinking the problem might be that Empty doesn't define a val template member: C:\code\d>type test.d void main() { auto t = new Tuple!(int,Tuple!(int))(); t.val!(0) = 1; t.val!(1) = 2; } struct Empty { } class Tuple( HeadType, TailType = Empty ) { alias HeadType Type; HeadType head; TailType tail; template val( int n, T : Empty = TailType ) { static if( n == 0 ) alias head val; else alias tail val; } template val( int n, T = TailType ) { static if( n == 0 ) alias head val; else alias tail.val!(n-1,TailType) val; } } C:\code\d>dmd test.d test.d(34): template identifier val is not a member of tail test.d(6): template instance test.Tuple!(int,Tuple).Tuple.val!(1) error instantiating test.d(6): cannot implicitly convert expression (2) of type int to test.Tuple!(int).Tuple C:\code\d>
Feb 09 2006
I think I'm merely running up against the limitations of 'alias' here. Can 'alias' be used to alias variables? And if so, what are the restrictions? The spec isn't of much use here. For reference, here is a shortened test case that exhibits the problem. Why can I alias 'i' but not 's.i'? Is it merely a scope issue? C:\code\d\bugs>type 145_2.d void main() { struct S { int i; } S s; int i; alias i a1; alias s.i a2; } C:\code\d\bugs>dmd 145_2.d 145_2.d(8): s.i is used as a type C:\code\d\bugs>
Feb 09 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sean Kelly schrieb am 2006-02-10:I think I'm merely running up against the limitations of 'alias' here. Can 'alias' be used to alias variables? And if so, what are the restrictions? The spec isn't of much use here. For reference, here is a shortened test case that exhibits the problem. Why can I alias 'i' but not 's.i'? Is it merely a scope issue? C:\code\d\bugs>type 145_2.d void main() { struct S { int i; } S s; int i; alias i a1; alias s.i a2; } C:\code\d\bugs>dmd 145_2.d 145_2.d(8): s.i is used as a typeAdded to DStress http://dstress.kuehne.cn/run/a/alias_29_A.d http://dstress.kuehne.cn/run/a/alias_29_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD7baN3w+/yD4P9tIRAjDeAJ9aP266uplXkaqBixhtYgi4UmQbtwCgujfT PPeXBt6Q/2IO0iljxfCEgwQ= =4AqM -----END PGP SIGNATURE-----
Feb 11 2006