Skip to content

Commit

Permalink
Merge pull request #2082 from 9rnsr/fix10178
Browse files Browse the repository at this point in the history
[REG2.063a] Issue 10178 - Compiler segfault with zero-length tuple comparison
  • Loading branch information
andralex authored and WalterBright committed May 27, 2013
1 parent 95032ff commit e7da997
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -12713,17 +12713,21 @@ Expression *EqualExp::semantic(Scope *sc)
TupleExp *tup1 = (TupleExp *)e1;
TupleExp *tup2 = (TupleExp *)e2;
size_t dim = tup1->exps->dim;
Expression *e = NULL;
if (dim != tup2->exps->dim)
{
error("mismatched tuple lengths, %d and %d", (int)dim, (int)tup2->exps->dim);
return new ErrorExp();
e = new ErrorExp();
}
else if (dim == 0)
{
// zero-length tuple comparison should always return true or false.
e = new IntegerExp(loc, (op == TOKequal), Type::tboolean);
}
else
{
Expressions *exps = new Expressions;
exps->setDim(dim);

Expression *e = NULL;
for (size_t i = 0; i < dim; i++)
{
Expression *ex1 = (*tup1->exps)[i];
Expand All @@ -12736,11 +12740,12 @@ Expression *EqualExp::semantic(Scope *sc)
else
e = new OrOrExp(loc, e, eeq);
}
assert(e);
e = combine(combine(tup1->e0, tup2->e0), e);
e = e->semantic(sc);
//printf("e = %s\n", e->toChars());
return e;
}
e = e->semantic(sc);
return e;
}

e = typeCombine(sc);
Expand Down
11 changes: 11 additions & 0 deletions test/runnable/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,17 @@ void test9873()
static assert(!__traits(compiles, tup1 == Seq!(1, "hi", [1,2])));
}

/***************************************************/
// 10178

void test10178()
{
struct S {}
S s;
assert((s.tupleof == s.tupleof) == true);
assert((s.tupleof != s.tupleof) == false);
}

/***************************************************/
// 9890

Expand Down

0 comments on commit e7da997

Please sign in to comment.