diff options
| author | gingerBill <bill@gingerbill.org> | 2019-07-07 14:38:11 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-07-07 14:38:11 +0100 |
| commit | d99ffe604f5dfca623f4973e7431b81a1bedfb77 (patch) | |
| tree | b0f78fb152fa1a8f8c4e662195c330868308a0d3 /src | |
| parent | b77c79294cfc7c5674c2e1c25291bf97ae42761f (diff) | |
Fix unions with zero variants
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_stmt.cpp | 5 | ||||
| -rw-r--r-- | src/ir.cpp | 8 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index a14aeeaaf..24f540930 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1710,11 +1710,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { error(vd->type, "Invalid use of a polymorphic type '%s' in variable declaration", str); gb_string_free(str); init_type = t_invalid; - } else if (is_type_empty_union(init_type)) { - gbString str = type_to_string(init_type); - error(vd->type, "An empty union '%s' cannot be instantiated in variable declaration", str); - gb_string_free(str); - init_type = t_invalid; } } diff --git a/src/ir.cpp b/src/ir.cpp index b06c041e4..870c7da42 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4008,8 +4008,12 @@ irValue *ir_emit_comp_against_nil(irProcedure *proc, TokenKind op_kind, irValue irValue *len = ir_map_len(proc, x); return ir_emit_comp(proc, op_kind, len, v_zero); } else if (is_type_union(t)) { - irValue *tag = ir_emit_union_tag_value(proc, x); - return ir_emit_comp(proc, op_kind, tag, v_zero); + if (type_size_of(t) == 0) { + return ir_emit_comp(proc, op_kind, v_zero, v_zero); + } else { + irValue *tag = ir_emit_union_tag_value(proc, x); + return ir_emit_comp(proc, op_kind, tag, v_zero); + } } else if (is_type_typeid(t)) { irValue *invalid_typeid = ir_value_constant(t_typeid, exact_value_i64(0)); return ir_emit_comp(proc, op_kind, x, invalid_typeid); |