diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-22 18:07:12 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-22 18:07:12 -0500 |
| commit | 903c957c7e686401e12bf52ad0ac00d0efa6fd30 (patch) | |
| tree | 604e15b5a14eadd46bce4e5ea1e5d16031c59b68 /src/types.c | |
| parent | 32cbf32c91688b93c40e457e61b29decb416a6e7 (diff) | |
Bugfix for `Success || Void` typechecking
Diffstat (limited to 'src/types.c')
| -rw-r--r-- | src/types.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/types.c b/src/types.c index 46df5c64..1ccb7952 100644 --- a/src/types.c +++ b/src/types.c @@ -144,6 +144,13 @@ PUREFUNC type_t *value_type(type_t *t) { return t; } +PUREFUNC bool is_discardable_type(type_t *t) { + if (t->tag == StructType) { + return (Match(t, StructType)->fields == NULL); + } + return (t->tag == VoidType || t->tag == AbortType || t->tag == ReturnType); +} + type_t *type_or_type(type_t *a, type_t *b) { if (!a) return b; if (!b) return a; @@ -153,6 +160,8 @@ type_t *type_or_type(type_t *a, type_t *b) { return a->tag == OptionalType ? a : Type(OptionalType, a); if (a->tag == ReturnType && b->tag == ReturnType) return Type(ReturnType, .ret = type_or_type(Match(a, ReturnType)->ret, Match(b, ReturnType)->ret)); + if ((a->tag == VoidType && is_discardable_type(b)) || (is_discardable_type(a) && b->tag == VoidType)) + return Type(VoidType); if (is_incomplete_type(a) && type_eq(b, most_complete_type(a, b))) return b; if (is_incomplete_type(b) && type_eq(a, most_complete_type(a, b))) return a; |
