From d629aa1df464bd1882954487bfaeb97981da8a35 Mon Sep 17 00:00:00 2001 From: k-hara Date: Tue, 13 May 2014 15:19:51 +0900 Subject: [PATCH] fix Issue 11333 - ICE: Cannot subtype 0-tuple with "alias this" --- src/expression.c | 7 +++++-- test/runnable/aliasthis.d | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/expression.c b/src/expression.c index 6ee7801be04f..d8588d2093cb 100644 --- a/src/expression.c +++ b/src/expression.c @@ -10902,12 +10902,15 @@ Expression *AssignExp::semantic(Scope *sc) //printf("e = (%s %s, %s), ", Token::tochars[e->op], e->toChars(), e->type->toChars()); //printf("arg = (%s, %s)\n", arg->toChars(), arg->type->toChars()); - if (!e->type->implicitConvTo(arg->type)) + if (!arg || !e->type->implicitConvTo(arg->type)) { // expand initializer to tuple if (expandAliasThisTuples(iexps, u) != -1) + { + if (iexps->dim <= u) + break; goto Lexpand; - + } goto Lnomatch; } } diff --git a/test/runnable/aliasthis.d b/test/runnable/aliasthis.d index 17cdf9525fe6..256fc19f3127 100644 --- a/test/runnable/aliasthis.d +++ b/test/runnable/aliasthis.d @@ -1586,6 +1586,32 @@ void test11261() } } +/***************************************************/ +// 11333 + +alias id11333(a...) = a; + +struct Unit11333 +{ + enum value = Unit11333.init.tupleof; + alias value this; +} + +void test11333() +{ + void foo() {} + + id11333!() unit; + unit = unit; // ok + foo(unit); // ok + + unit = Unit11333.value; // ok + foo(Unit11333.value); // ok + + Unit11333 unit2; + unit = unit2; // ok <- segfault +} + /***************************************************/ // 11800 @@ -1725,6 +1751,7 @@ int main() test10004(); test10180(); test10456(); + test11333(); test11800(); printf("Success\n");