Fix nil assignment to unions

This commit is contained in:
Ginger Bill
2017-07-29 14:23:34 +01:00
parent fbd27d7c45
commit 7bd62481ad
+6 -12
View File
@@ -4362,7 +4362,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
} break;
case Type_Union:
{
if (!is_operand_nil(*operand) && !is_operand_undef(*operand)) {
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
defer (gb_temp_arena_memory_end(tmp));
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 (j > 0 && success_count > 2) gb_printf_err(", ");
if (j == success_count-1) {
if (success_count == 2) {
if (success_count == 2) gb_printf_err(" ");
gb_printf_err("or ");
} else {
gb_printf_err(" or ");
}
}
gbString str = type_to_string(t->Union.variants[i]);
gb_printf_err("`%s`", str);
@@ -4426,11 +4423,8 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
Type *v = t->Union.variants[i];
if (i > 0 && count > 2) gb_printf_err(", ");
if (i == count-1) {
if (count == 2) {
if (count == 2) gb_printf_err(" ");
gb_printf_err("or ");
} else {
gb_printf_err("or ");
}
}
gbString str = type_to_string(v);
gb_printf_err("`%s`", str);
@@ -4441,7 +4435,6 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
}
return;
}
}
/* fallthrough */
@@ -4449,12 +4442,13 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
default:
if (is_type_untyped_undef(operand->type) && type_has_undef(target_type)) {
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;
convert_untyped_error(c, operand, target_type);
return;
}
target_type = t_untyped_nil;
break;
}