diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-02-12 18:27:34 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-02-12 18:27:34 -0500 |
| commit | 0931b85bd04fb671dce980728a3692de2bd496a5 (patch) | |
| tree | 685a16034c2908fb9f6437d546db40c9f09ecf65 /src | |
| parent | 79ec5a02875bb4af0dbcc186ffc03e693938db9a (diff) | |
| download | zig-0931b85bd04fb671dce980728a3692de2bd496a5.tar.gz zig-0931b85bd04fb671dce980728a3692de2bd496a5.zip | |
fix crash when return value is ??void
closes #258
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 72b1ae055b..a346614e56 100644 --- 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; |
