From f1aa78c022eb3f96a0d97e28ce9c35edbe7c45a1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 19 Aug 2021 10:13:10 -0700 Subject: [Wasm GC] Nulls compare equal regardless of type (#4094) --- src/wasm/literal.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index c7a9ca844..8beae78bd 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -338,14 +338,17 @@ void Literal::getBits(uint8_t (&buf)[16]) const { } bool Literal::operator==(const Literal& other) const { + // The types must be identical, unless both are references - in that case, + // nulls of different types *do* compare equal. + if (type.isRef() && other.type.isRef() && (isNull() || other.isNull())) { + return isNull() && other.isNull(); + } if (type != other.type) { return false; } auto compareRef = [&]() { assert(type.isRef()); - if (isNull() || other.isNull()) { - return isNull() == other.isNull(); - } + // Note that we've already handled nulls earlier. if (type.isFunction()) { assert(func.is() && other.func.is()); return func == other.func; -- cgit v1.2.3