@@ -744,10 +744,11 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
744744 * Params:
745745 * t = element type
746746 * dim = max number of elements
747+ * simple = true if array of simple elements
747748 * Returns:
748749 * # of elements in array
749750 */
750- size_t array (Type t, size_t dim)
751+ size_t array (Type t, size_t dim, ref bool simple )
751752 {
752753 // printf(" type %s i %d dim %d dil.length = %d\n", t.toChars(), cast(int)i, cast(int)dim, cast(int)dil.length);
753754 auto tn = t.nextOf().toBasetype();
@@ -789,14 +790,30 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
789790 if (tnsa && di.initializer.isExpInitializer())
790791 {
791792 // no braces enclosing array initializer, so recurse
792- array(tnsa, nelems);
793+ array(tnsa, nelems, simple );
793794 }
794795 else if (auto tns = tn.isTypeStruct())
795796 {
796- if (di.initializer.isExpInitializer())
797+ if (auto ei = di.initializer.isExpInitializer())
797798 {
798799 // 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+ }
800817 }
801818 else
802819 dil[n].initializer = elem(di.initializer);
@@ -814,7 +831,8 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
814831 }
815832
816833 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);
818836
819837 if (errors)
820838 return err ();
@@ -845,7 +863,7 @@ extern(C++) Initializer initializerSemantic(Initializer init, Scope* sc, ref Typ
845863 /* If an array of simple elements, replace with an ArrayInitializer
846864 */
847865 auto tnb = tn.toBasetype();
848- if (! ( tnb.isTypeSArray() || tnb.isTypeStruct()))
866+ if (! tnb.isTypeSArray() && ( ! tnb.isTypeStruct() || simple ))
849867 {
850868 auto ai = new ArrayInitializer(ci.loc);
851869 ai.dim = cast (uint ) dil.length;
0 commit comments