diff --git a/src/ctfeexpr.c b/src/ctfeexpr.c index 7d3bbbb7c550..b8cb10192871 100644 --- a/src/ctfeexpr.c +++ b/src/ctfeexpr.c @@ -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; @@ -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; diff --git a/test/compilable/interpret3.d b/test/compilable/interpret3.d index 0fa4ace896b7..7353add91f5c 100644 --- a/test/compilable/interpret3.d +++ b/test/compilable/interpret3.d @@ -4108,6 +4108,12 @@ int classtest3() static assert(classtest3()); +/************************************************** + 11587 AA compare +**************************************************/ + +static assert([1:2, 3:4] == [3:4, 1:2]); + /************************************************** 7147 typeid() **************************************************/