diff --git a/src/expression.c b/src/expression.c index cb23b42d5f2d..613cdca76251 100644 --- a/src/expression.c +++ b/src/expression.c @@ -3572,8 +3572,11 @@ bool NullExp::equals(RootObject *o) if (o && o->dyncast() == DYNCAST_EXPRESSION) { Expression *e = (Expression *)o; - if (e->op == TOKnull) + if (e->op == TOKnull && + type->equals(e->type)) + { return true; + } } return false; } @@ -4022,6 +4025,11 @@ bool ArrayLiteralExp::equals(RootObject *o) ArrayLiteralExp *ae = (ArrayLiteralExp *)o; if (elements->dim != ae->elements->dim) return false; + if (elements->dim == 0 && + !type->equals(ae->type)) + { + return false; + } for (size_t i = 0; i < elements->dim; i++) { Expression *e1 = (*elements)[i]; @@ -4273,7 +4281,7 @@ bool StructLiteralExp::equals(RootObject *o) ((Expression *)o)->op == TOKstructliteral) { StructLiteralExp *se = (StructLiteralExp *)o; - if (sd != se->sd) + if (!type->equals(se->type)) return false; if (elements->dim != se->elements->dim) return false; diff --git a/src/template.c b/src/template.c index 063a708d4192..84148173474e 100644 --- a/src/template.c +++ b/src/template.c @@ -292,21 +292,20 @@ int match(RootObject *o1, RootObject *o2) { //printf("t1 = %s\n", t1->toChars()); //printf("t2 = %s\n", t2->toChars()); - if (!t2 || !t1->equals(t2)) + if (!t2) + goto Lnomatch; + if (!t1->equals(t2)) goto Lnomatch; } else if (e1) { -#if 0 - if (e1 && e2) - { - printf("match %d\n", e1->equals(e2)); - printf("\te1 = %p %s %s %s\n", e1, e1->type->toChars(), Token::toChars(e1->op), e1->toChars()); - printf("\te2 = %p %s %s %s\n", e2, e2->type->toChars(), Token::toChars(e2->op), e2->toChars()); - } -#endif if (!e2) goto Lnomatch; +#if 0 + printf("match %d\n", e1->equals(e2)); + printf("\te1 = %p %s %s %s\n", e1, e1->type->toChars(), Token::toChars(e1->op), e1->toChars()); + printf("\te2 = %p %s %s %s\n", e2, e2->type->toChars(), Token::toChars(e2->op), e2->toChars()); +#endif if (!e1->equals(e2)) goto Lnomatch; } diff --git a/test/runnable/template9.d b/test/runnable/template9.d index da2cdc7adb21..7ee0a81a38e0 100644 --- a/test/runnable/template9.d +++ b/test/runnable/template9.d @@ -3854,6 +3854,33 @@ void test13223() //static assert(is(typeof(f5(null)) == void[])); } +/******************************************/ +// 13252 + +alias TypeTuple13252(T...) = T; + +static assert(is(typeof(TypeTuple13252!(cast(int )1)[0]) == int )); +static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long)); + +static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float )); +static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double)); + +static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat )); +static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble)); + +static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string )); +static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG + +static assert(is(typeof(TypeTuple13252!(cast(wstring)"abc")[0]) == wstring)); +static assert(is(typeof(TypeTuple13252!(cast(dstring)"abc")[0]) == dstring)); + +static assert(is(typeof(TypeTuple13252!(cast(int[] )[])[0]) == int[] )); +static assert(is(typeof(TypeTuple13252!(cast(long[])[])[0]) == long[])); // OK <- NG + +struct S13252 { } +static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13252))); +static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG + /******************************************/ int main()