mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Improve type checking on polymorphic unions
This commit is contained in:
@@ -674,6 +674,10 @@ gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *no
|
|||||||
for_array(i, ut->variants) {
|
for_array(i, ut->variants) {
|
||||||
Ast *node = ut->variants[i];
|
Ast *node = ut->variants[i];
|
||||||
Type *t = check_type_expr(ctx, node, nullptr);
|
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) {
|
if (t != nullptr && t != t_invalid) {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
t = default_type(t);
|
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) {
|
for_array(j, variants) {
|
||||||
if (are_types_identical(t, variants[j])) {
|
if (are_types_identical(t, variants[j])) {
|
||||||
ok = false;
|
ok = false;
|
||||||
|
ERROR_BLOCK();
|
||||||
gbString str = type_to_string(t);
|
gbString str = type_to_string(t);
|
||||||
error(node, "Duplicate variant type '%s'", str);
|
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);
|
gb_string_free(str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user