Bug 1064 – Tuples are not expanded in array initializers
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-03-15T14:36:00Z
Last change time
2015-06-09T05:10:44Z
Keywords
pull, rejects-valid
Assigned to
yebblies
Creator
onlystupidspamhere
Comments
Comment #0 by onlystupidspamhere — 2007-03-15T14:36:52Z
template T(E...) { alias E T; }
// Error: cannot implicitly convert expression (tuple(1,2))
// of type (int, int) to int
//int[] a = [ T!(1,2) ];
// Error: cannot implicitly convert expression (tuple(1))
// of type (int) to int
//int[] a = [ T!(1) ];
struct S {
// Error: cannot implicitly convert expression (tuple(1,2))
// of type (int, int) to int
//static int[] a = [ T!(1,2) ];
// works
static int[] a = [ 1,2 ];
}
// works
int[] a = [ 1,2 ];
void main() {
// works
int[] a = [ T!(1,2) ];
// works
int[] b = [ T!(1) ];
// Error: cannot implicitly convert expression ([1,2])
// of type int[2] to int
//auto c = [ T!(1,2) ];
// Error: tuple index 1 exceeds 1
// Error: cannot implicitly convert expression ([1])
// of type int[1] to int
//auto d = [ T!(1) ];
}
I suppose they all should work. It's possible to do (on the global scope)
//int[] a = [ T!(1,2)[0], T!(1,2)[1] ];
but an arbitrary length tuple does not compile.
Comment #1 by rsinfu — 2010-10-27T15:23:45Z
*** Issue 3263 has been marked as a duplicate of this issue. ***