From ede5c9885bea70487c3fad4606ecfec3923d60de Mon Sep 17 00:00:00 2001 From: k-hara Date: Fri, 13 Jan 2012 15:20:36 +0900 Subject: [PATCH] Issue 7285 - Implicit fixed-size array cast --- src/cast.c | 4 ++++ test/runnable/xtest46.d | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/cast.c b/src/cast.c index ca8dc3c33dde..47ff9e31243d 100644 --- a/src/cast.c +++ b/src/cast.c @@ -1819,10 +1819,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 diff --git a/test/runnable/xtest46.d b/test/runnable/xtest46.d index ac02fae473d9..b5bd8ec9f542 100644 --- a/test/runnable/xtest46.d +++ b/test/runnable/xtest46.d @@ -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() @@ -4590,6 +4607,7 @@ int main() test7168(); test7170(); test7196(); + test7285(); printf("Success\n"); return 0;