Skip to content

Commit 44d7881

Browse files
author
Walter Bright
committed
bugzilla 2451 Adding structs that use opAssign or postblit to an AA is broken
1 parent c797f2d commit 44d7881

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/expression.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8961,7 +8961,26 @@ Expression *AssignExp::semantic(Scope *sc)
89618961
if (op == TOKassign)
89628962
{
89638963
Expression *e = op_overload(sc);
8964-
if (e)
8964+
if (e && e1->op == TOKindex &&
8965+
((IndexExp *)e1)->e1->type->toBasetype()->ty == Taarray)
8966+
{
8967+
// Deal with AAs (Bugzilla 2451)
8968+
// Rewrite as:
8969+
// e1 = (typeof(e2) tmp = void, tmp = e2, tmp);
8970+
Identifier *id = Lexer::uniqueId("__aatmp");
8971+
VarDeclaration *v = new VarDeclaration(loc, e2->type,
8972+
id, new VoidInitializer(NULL));
8973+
v->storage_class |= STCctfe;
8974+
8975+
Expression *de = new DeclarationExp(loc, v);
8976+
VarExp *ve = new VarExp(loc, v);
8977+
8978+
AssignExp *ae = new AssignExp(loc, ve, e2);
8979+
e = ae->op_overload(sc);
8980+
e2 = new CommaExp(loc, new CommaExp(loc, de, e), ve);
8981+
e2 = e2->semantic(sc);
8982+
}
8983+
else if (e)
89658984
return e;
89668985
}
89678986
else if (op == TOKconstruct && !refinit)

0 commit comments

Comments
 (0)