diff --git a/dmd/expression.c b/dmd/expression.c index add23473..dc73cae3 100644 --- a/dmd/expression.c +++ b/dmd/expression.c @@ -8420,10 +8420,15 @@ Expression *CatAssignExp::semantic(Scope *sc) e2->rvalue(); + Type *tb1next = tb1->nextOf(); + if ((tb1->ty == Tarray) && (tb2->ty == Tarray || tb2->ty == Tsarray) && - e2->implicitConvTo(e1->type) - //e1->type->next->equals(e2->type->next) + (e2->implicitConvTo(e1->type) +#if DMDV2 + || tb2->nextOf()->implicitConvTo(tb1next) +#endif + ) ) { // Append array e2 = e2->castTo(sc, e1->type); @@ -8431,18 +8436,30 @@ Expression *CatAssignExp::semantic(Scope *sc) e = this; } else if ((tb1->ty == Tarray) && - e2->implicitConvTo(tb1->nextOf()) + e2->implicitConvTo(tb1next) ) { // Append element - e2 = e2->castTo(sc, tb1->nextOf()); + e2 = e2->castTo(sc, tb1next); type = e1->type; e = this; } + else if (tb1->ty == Tarray && + (tb1next->ty == Tchar || tb1next->ty == Twchar) && + e2->implicitConvTo(Type::tdchar) + ) + { // Append dchar to char[] or wchar[] + e2 = e2->castTo(sc, Type::tdchar); + type = e1->type; + e = this; + + /* Do not allow appending wchar to char[] because if wchar happens + * to be a surrogate pair, nothing good can result. + */ + } else { error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars()); - type = Type::tint32; - e = this; + e = new ErrorExp(); } return e; } @@ -8464,6 +8481,15 @@ Expression *MulAssignExp::semantic(Scope *sc) if (e) return e; +#if DMDV2 + if (e1->op == TOKarraylength) + { + e = ArrayLengthExp::rewriteOpAssign(this); + e = e->semantic(sc); + return e; + } +#endif + if (e1->op == TOKslice) { // T[] -= ... typeCombine(sc); @@ -8531,6 +8557,15 @@ Expression *DivAssignExp::semantic(Scope *sc) if (e) return e; +#if DMDV2 + if (e1->op == TOKarraylength) + { + e = ArrayLengthExp::rewriteOpAssign(this); + e = e->semantic(sc); + return e; + } +#endif + if (e1->op == TOKslice) { // T[] -= ... typeCombine(sc);