aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-03-12 12:39:31 +0000
committergingerBill <bill@gingerbill.org>2023-03-12 12:39:31 +0000
commitbf91fcc6f72b854b6a63403f38b5c8d6817cb10d (patch)
treea6dfecbf639b918288b533e520dd83dcb3bb1fee /src/check_type.cpp
parentc39bd7e0894d3ef9a8f1ac9b487710cc41baf629 (diff)
Improve type checking on polymorphic unions
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index fabbe54c4..7444f88be 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -674,6 +674,10 @@ gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *no
for_array(i, ut->variants) {
Ast *node = ut->variants[i];
Type *t = check_type_expr(ctx, node, nullptr);
+ if (union_type->Union.is_polymorphic && poly_operands == nullptr) {
+ // NOTE(bill): don't add any variants if this is this is an unspecialized polymorphic record
+ continue;
+ }
if (t != nullptr && t != t_invalid) {
bool ok = true;
t = default_type(t);
@@ -686,8 +690,12 @@ gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *no
for_array(j, variants) {
if (are_types_identical(t, variants[j])) {
ok = false;
+ ERROR_BLOCK();
gbString str = type_to_string(t);
error(node, "Duplicate variant type '%s'", str);
+ if (j < ut->variants.count) {
+ error_line("\tPrevious found at %s\n", token_pos_to_string(ast_token(ut->variants[j]).pos));
+ }
gb_string_free(str);
break;
}