Skip to content

Commit

Permalink
Fix issue 22632 - Crash happens when CTFE compares an associative arr…
Browse files Browse the repository at this point in the history
…ay to null using ==
  • Loading branch information
wolframw committed Dec 28, 2021
1 parent 8efc7eb commit c238e37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,15 @@ private int ctfeRawCmp(const ref Loc loc, Expression e1, Expression e2, bool ide
mem.xfree(used);
return 0;
}
else if (e1.op == EXP.assocArrayLiteral && e2.op == EXP.null_)
{
return e1.isAssocArrayLiteralExp.keys.dim != 0;
}
else if (e1.op == EXP.null_ && e2.op == EXP.assocArrayLiteral)
{
return e2.isAssocArrayLiteralExp.keys.dim != 0;
}

error(loc, "CTFE internal error: bad compare of `%s` and `%s`", e1.toChars(), e2.toChars());
assert(0);
}
Expand Down
4 changes: 4 additions & 0 deletions test/compilable/test22632.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://issues.dlang.org/show_bug.cgi?id=22632

static assert(["one": 1] != null);
static assert(null != ["one": 1]);

0 comments on commit c238e37

Please sign in to comment.