@@ -744,10 +744,11 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
744
744
* Params:
745
745
* t = element type
746
746
* dim = max number of elements
747
+ * simple = true if array of simple elements
747
748
* Returns:
748
749
* # of elements in array
749
750
*/
750
- size_t array (Type t, size_t dim)
751
+ size_t array (Type t, size_t dim, ref bool simple )
751
752
{
752
753
// printf(" type %s i %d dim %d dil.length = %d\n", t.toChars(), cast(int)i, cast(int)dim, cast(int)dil.length);
753
754
auto tn = t.nextOf().toBasetype();
@@ -789,14 +790,30 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
789
790
if (tnsa && di.initializer.isExpInitializer())
790
791
{
791
792
// no braces enclosing array initializer, so recurse
792
- array(tnsa, nelems);
793
+ array(tnsa, nelems, simple );
793
794
}
794
795
else if (auto tns = tn.isTypeStruct())
795
796
{
796
- if (di.initializer.isExpInitializer())
797
+ if (auto ei = di.initializer.isExpInitializer())
797
798
{
798
799
// no braces enclosing struct initializer
799
- dil[n].initializer = structs(tns);
800
+
801
+ /* Disambiguate between an exp representing the entire
802
+ * struct, and an exp representing the first field of the struct
803
+ */
804
+ if (needInterpret)
805
+ sc = sc.startCTFE();
806
+ ei.exp = ei.exp.expressionSemantic(sc);
807
+ ei.exp = resolveProperties(sc, ei.exp);
808
+ if (needInterpret)
809
+ sc = sc.endCTFE();
810
+ if (ei.exp.implicitConvTo(tn))
811
+ di.initializer = elem(di.initializer); // the whole struct
812
+ else
813
+ {
814
+ simple = false ;
815
+ dil[n].initializer = structs(tns); // the first field
816
+ }
800
817
}
801
818
else
802
819
dil[n].initializer = elem(di.initializer);
@@ -814,7 +831,8 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
814
831
}
815
832
816
833
size_t dim = tsa.isIncomplete() ? dil.length : cast (size_t )tsa.dim.toInteger();
817
- auto newdim = array(t, dim);
834
+ bool simple = true ;
835
+ auto newdim = array(t, dim, simple);
818
836
819
837
if (errors)
820
838
return err ();
@@ -845,7 +863,7 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
845
863
/* If an array of simple elements, replace with an ArrayInitializer
846
864
*/
847
865
auto tnb = tn.toBasetype();
848
- if (! ( tnb.isTypeSArray() || tnb.isTypeStruct()))
866
+ if (! tnb.isTypeSArray() && ( ! tnb.isTypeStruct() || simple ))
849
867
{
850
868
auto ai = new ArrayInitializer(ci.loc);
851
869
ai.dim = cast (uint ) dil.length;
0 commit comments