mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Fix nil assignment to unions
This commit is contained in:
+7
-13
@@ -4362,7 +4362,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Type_Union:
|
case Type_Union:
|
||||||
{
|
if (!is_operand_nil(*operand) && !is_operand_undef(*operand)) {
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
|
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
|
||||||
defer (gb_temp_arena_memory_end(tmp));
|
defer (gb_temp_arena_memory_end(tmp));
|
||||||
isize count = t->Union.variants.count;
|
isize count = t->Union.variants.count;
|
||||||
@@ -4400,11 +4400,8 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
|
|||||||
if (scores[i] == 0) continue;
|
if (scores[i] == 0) continue;
|
||||||
if (j > 0 && success_count > 2) gb_printf_err(", ");
|
if (j > 0 && success_count > 2) gb_printf_err(", ");
|
||||||
if (j == success_count-1) {
|
if (j == success_count-1) {
|
||||||
if (success_count == 2) {
|
if (success_count == 2) gb_printf_err(" ");
|
||||||
gb_printf_err(" or ");
|
gb_printf_err("or ");
|
||||||
} else {
|
|
||||||
gb_printf_err(" or ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gbString str = type_to_string(t->Union.variants[i]);
|
gbString str = type_to_string(t->Union.variants[i]);
|
||||||
gb_printf_err("`%s`", str);
|
gb_printf_err("`%s`", str);
|
||||||
@@ -4426,12 +4423,9 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
|
|||||||
Type *v = t->Union.variants[i];
|
Type *v = t->Union.variants[i];
|
||||||
if (i > 0 && count > 2) gb_printf_err(", ");
|
if (i > 0 && count > 2) gb_printf_err(", ");
|
||||||
if (i == count-1) {
|
if (i == count-1) {
|
||||||
if (count == 2) {
|
if (count == 2) gb_printf_err(" ");
|
||||||
gb_printf_err(" or ");
|
|
||||||
} else {
|
|
||||||
gb_printf_err("or ");
|
gb_printf_err("or ");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
gbString str = type_to_string(v);
|
gbString str = type_to_string(v);
|
||||||
gb_printf_err("`%s`", str);
|
gb_printf_err("`%s`", str);
|
||||||
gb_string_free(str);
|
gb_string_free(str);
|
||||||
@@ -4441,7 +4435,6 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
@@ -4449,12 +4442,13 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
|
|||||||
default:
|
default:
|
||||||
if (is_type_untyped_undef(operand->type) && type_has_undef(target_type)) {
|
if (is_type_untyped_undef(operand->type) && type_has_undef(target_type)) {
|
||||||
target_type = t_untyped_undef;
|
target_type = t_untyped_undef;
|
||||||
} else if (!is_type_untyped_nil(operand->type) || !type_has_nil(target_type)) {
|
} else if (is_type_untyped_nil(operand->type) && type_has_nil(target_type)) {
|
||||||
|
target_type = t_untyped_nil;
|
||||||
|
} else {
|
||||||
operand->mode = Addressing_Invalid;
|
operand->mode = Addressing_Invalid;
|
||||||
convert_untyped_error(c, operand, target_type);
|
convert_untyped_error(c, operand, target_type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
target_type = t_untyped_nil;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user