Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 11587 - Cannot compare AAs at compile time #2869

Merged
merged 1 commit into from Nov 25, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/ctfeexpr.c
Expand Up @@ -1130,6 +1130,7 @@ bool isCtfeComparable(Expression *e)
x->op != TOKdelegate &&
x->op != TOKarrayliteral &&
x->op != TOKstructliteral &&
x->op != TOKassocarrayliteral &&
x->op != TOKclassreference)
{
return false;
Expand Down Expand Up @@ -1461,6 +1462,43 @@ int ctfeRawCmp(Loc loc, Expression *e1, Expression *e2)
return 0; // All elements are equal
}
}
if (e1->op == TOKassocarrayliteral && e2->op == TOKassocarrayliteral)
{
AssocArrayLiteralExp *es1 = (AssocArrayLiteralExp *)e1;
AssocArrayLiteralExp *es2 = (AssocArrayLiteralExp *)e2;

int dim = es1->keys->dim;
if (es2->keys->dim != dim)
return 1;

bool *used = (bool *)mem.malloc(sizeof(bool) * dim);
memset(used, 0, sizeof(bool) * dim);

for (size_t i = 0; i < dim; ++i)
{
Expression *k1 = (*es1->keys)[i];
Expression *v1 = (*es1->values)[i];

for (size_t j = 0; j < dim; ++j)
{
if (used[j])
continue;
Expression *k2 = (*es2->keys)[j];
Expression *v2 = (*es2->values)[j];

if (ctfeRawCmp(loc, k1, k2))
continue;
used[j] = true;
if (ctfeRawCmp(loc, v1, v2))
{
mem.free(used);
return 1;
}
}
}
mem.free(used);
return 0;
}
error(loc, "CTFE internal error: bad compare");
assert(0);
return 0;
Expand Down
6 changes: 6 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -4108,6 +4108,12 @@ int classtest3()

static assert(classtest3());

/**************************************************
11587 AA compare
**************************************************/

static assert([1:2, 3:4] == [3:4, 1:2]);

/**************************************************
7147 typeid()
**************************************************/
Expand Down