diff --git a/src/cast.c b/src/cast.c index 520fcc1bfc6c..080c1fa41b19 100644 --- a/src/cast.c +++ b/src/cast.c @@ -2840,7 +2840,9 @@ bool typeMerge(Scope *sc, TOK op, Type **pt, Expression **pe1, Expression **pe2) else if ((t1->ty == Tsarray || t1->ty == Tarray) && (m = t1->implicitConvTo(t2)) != MATCHnomatch) { - if (t1->ty == Tsarray && e2->op == TOKarrayliteral) + // Bugzilla 7285: Tsarray op [x, y, ...] should to be Tsarray + // Bugzilla 14737: Tsarray ~ [x, y, ...] should to be Tarray + if (t1->ty == Tsarray && e2->op == TOKarrayliteral && op != TOKcat) goto Lt1; if (m == MATCHconst && (op == TOKaddass || op == TOKminass || op == TOKmulass || @@ -2856,7 +2858,8 @@ bool typeMerge(Scope *sc, TOK op, Type **pt, Expression **pe1, Expression **pe2) } else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) { - if (t2->ty == Tsarray && e1->op == TOKarrayliteral) + // Bugzilla 7285 & 14737 + if (t2->ty == Tsarray && e1->op == TOKarrayliteral && op != TOKcat) goto Lt2; goto Lt1; } diff --git a/test/runnable/xtest46.d b/test/runnable/xtest46.d index 9d9823f05d1c..8fc8ab86c6d2 100644 --- a/test/runnable/xtest46.d +++ b/test/runnable/xtest46.d @@ -5636,6 +5636,30 @@ void test7285() auto sa = spam7285(); } +/***************************************************/ +// 14737 + +void test14737() +{ + // compile-time + enum string[2] a1 = ["d", "e"]; + enum b1x = ["a", "b", "c"] ~ a1; // Tarray vs Tsarray + enum b1y = a1 ~ ["a", "b", "c"]; // Tsarray vs Tarray + static assert(is(typeof(b1x) == string[])); + static assert(is(typeof(b1y) == string[])); + static assert(b1x == ["a", "b", "c", "d", "e"]); + static assert(b1y == ["d", "e", "a", "b", "c"]); + + // runtime + string[2] a2 = ["d", "e"]; + auto b2x = ["a", "b", "c"] ~ a2; // Tarray vs Tsarray + auto b2y = a2 ~ ["a", "b", "c"]; // Tsarray vs Tarray + static assert(is(typeof(b2x) == string[])); + static assert(is(typeof(b2y) == string[])); + assert(b2x == ["a", "b", "c", "d", "e"]); + assert(b2y == ["d", "e", "a", "b", "c"]); +} + /***************************************************/ // 7321 @@ -7698,6 +7722,7 @@ int main() test7170(); test7196(); test7285(); + test14737(); test7321(); test3282(); test7534();