zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 0931b85bd04fb671dce980728a3692de2bd496a5 (tree)
parent 79ec5a02875bb4af0dbcc186ffc03e693938db9a
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sun, 12 Feb 2017 18:27:34 -0500

fix crash when return value is ??void

closes #258

Diffstat:
Msrc/ir.cpp | 17++++++++++++++++-
Mtest/run_tests.cpp | 5+++++
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/ir.cpp b/src/ir.cpp @@ -9985,8 +9985,23 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, if (value->value.type->id == TypeTableEntryIdInvalid) return ira->codegen->builtin_types.entry_invalid; - // This will be a pointer type because test null IR instruction operates on a pointer to a thing. TypeTableEntry *ptr_type = value->value.type; + if (ptr_type->id == TypeTableEntryIdMetaType) { + // surprise! actually this is just ??T not an unwrap maybe instruction + TypeTableEntry *ptr_type_ptr = ir_resolve_type(ira, value); + assert(ptr_type_ptr->id == TypeTableEntryIdPointer); + TypeTableEntry *child_type = ptr_type_ptr->data.pointer.child_type; + type_ensure_zero_bits_known(ira->codegen, child_type); + TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type); + TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1); + TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, layer2, true); + + IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope, + unwrap_maybe_instruction->base.source_node, result_type); + ir_link_new_instruction(const_instr, &unwrap_maybe_instruction->base); + return const_instr->value.type; + } + assert(ptr_type->id == TypeTableEntryIdPointer); TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; diff --git a/test/run_tests.cpp b/test/run_tests.cpp @@ -1622,6 +1622,11 @@ fn bar(a: i32, b: []const u8) { ".tmp_source.zig:8:5: error: found compile log statement", ".tmp_source.zig:3:17: note: called from here"); + add_compile_fail_case("double ?? on main return value", R"SOURCE( +pub fn main(args: [][]u8) -> ??void { +} + )SOURCE", 1, ".tmp_source.zig:2:30: error: expected return type of main to be '%void', instead is '??void'"); + } //////////////////////////////////////////////////////////////////////////////