aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-03 13:17:16 +0100
committergingerBill <bill@gingerbill.org>2021-05-03 13:17:16 +0100
commit518ecaf9c909bf2fd372fd758a5075f603b07d75 (patch)
treed82e6aaf0b9cbdd5bb523ad7cb39f90eb11c398c /src/types.cpp
parent77e2e1e1d02bf1755004f3a92457b2850a91f80c (diff)
Allow `union`s to be comparable if all their variants are comparable
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp18
1 files changed, 17 insertions, 1 deletions
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);