Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions test/runnable/template9.d
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down