Skip to content

Commit

Permalink
Merge pull request #4776 from 9rnsr/fix14737
Browse files Browse the repository at this point in the history
[REG2.058] Issue 14737 - A concatenation of array literal and static array should make dynamic array
  • Loading branch information
WalterBright committed Jun 26, 2015
2 parents d34aa50 + 0510166 commit d8eb139
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cast.c
Expand Up @@ -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 ||
Expand All @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -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

Expand Down Expand Up @@ -7698,6 +7722,7 @@ int main()
test7170();
test7196();
test7285();
test14737();
test7321();
test3282();
test7534();
Expand Down

0 comments on commit d8eb139

Please sign in to comment.