http://d.puremagic.com/issues/show_bug.cgi?id=11206
Summary: static array can be implicitly built from items, when nested in aggregate Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: monarchdo...@gmail.com --- Comment #0 from monarchdo...@gmail.com 2013-10-09 07:22:40 PDT --- Just to be clear, I'm not talking about "initial construction", where, eg, this is correct: //---- alias ARR = int[1]; struct S{int i;this(int){}} struct AGG(T) { T t; } void main() { S s1 = S(1); //Explicit, OK S s2 = 1; //Implicit, OK ARR arr1 = [1]; //Explicit, OK ARR arr2 = 1; //Implicit, OK } //---- This is OK: The table makes an implicit construction, thanks to an explicit type declaration. However, if the table is nested inside an aggregate, then this should not happen: Aggregate construction requires an exact type match (possibly via alias this), *However*, individual elements *may not* be implicitly constructed from pass in arguments: //---- void main() { AGG!S ts2 = AGG!S(S(2)); //Explicit. Good. AGG!S ts1 = AGG!S(1); //NO! ILLEGAL REQUEST FOR IMPLICIT CONSTRUCTION! AGG!ARR tarr1 = AGG!ARR([1]); //Explicit is good AGG!ARR tarr1 = AGG!ARR(1); //This works...? [HERE] } //---- [HERE]: This is a violation of the type system. With aggregate initialization, each argument is supposed to match the type of the aggregated element, or be *implicitly*castable* to said element. In the case of "element => static array element", we have neither. static arrays are the *only* type that allow this. I think making an exception for static arrays is surprising and wrong. It should be rejected. Related: http://d.puremagic.com/issues/show_bug.cgi?id=10973 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------