From 518ecaf9c909bf2fd372fd758a5075f603b07d75 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 May 2021 13:17:16 +0100 Subject: Allow `union`s to be comparable if all their variants are comparable --- src/types.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index 7b5b81c43..5e4370f8a 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1544,6 +1544,9 @@ bool is_type_valid_for_keys(Type *t) { if (is_type_untyped(t)) { return false; } + if (t->kind == Type_Union) { + return false; + } return is_type_comparable(t); } @@ -1915,6 +1918,18 @@ bool is_type_comparable(Type *t) { } } return true; + + case Type_Union: + if (type_size_of(t) == 0) { + return false; + } + for_array(i, t->Union.variants) { + Type *v = t->Union.variants[i]; + if (!is_type_comparable(v)) { + return false; + } + } + return true; } return false; } @@ -1959,7 +1974,8 @@ bool is_type_simple_compare(Type *t) { return false; } } - return true; + // make it dumb on purpose + return t->Union.variants.count == 1; case Type_SimdVector: return is_type_simple_compare(t->SimdVector.elem); -- cgit v1.2.3