Skip to content

Commit

Permalink
Merge pull request #618 from 9rnsr/fix7285
Browse files Browse the repository at this point in the history
Issue 7285 - Implicit fixed-size array cast
  • Loading branch information
WalterBright committed Jan 15, 2012
2 parents 83d567e + ede5c98 commit 61d4b88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cast.c
Expand Up @@ -1831,10 +1831,14 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
}
else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2))
{
if (t1->ty == Tsarray && e2->op == TOKarrayliteral)
goto Lt1;
goto Lt2;
}
else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1))
{
if (t2->ty == Tsarray && e1->op == TOKarrayliteral)
goto Lt2;
goto Lt1;
}
/* If one is mutable and the other invariant, then retry
Expand Down
18 changes: 18 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -4379,6 +4379,23 @@ void test7196()
auto y = (&foo7196)(1.0); // fail
}

/***************************************************/
// 7285

int[2] spam7285()
{
int[2] ab;
if (true)
return (true) ? ab : [0, 0]; // Error
else
return (true) ? [0, 0] : ab; // OK
}

void test7285()
{
auto sa = spam7285();
}

/***************************************************/

int main()
Expand Down Expand Up @@ -4590,6 +4607,7 @@ int main()
test7168();
test7170();
test7196();
test7285();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 61d4b88

Please sign in to comment.