| ... | @@ -15406,6 +15406,12 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns | ... | @@ -15406,6 +15406,12 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 15406 | } | 15406 | } |
| 15407 | if (instr_is_comptime(ptr)) { | 15407 | if (instr_is_comptime(ptr)) { |
| 15408 | if (ptr->value->special == ConstValSpecialUndef) { | 15408 | if (ptr->value->special == ConstValSpecialUndef) { |
| | 15409 | // If we are in a TypeOf call, we return an undefined value instead of erroring |
| | 15410 | // since we know the type. |
| | 15411 | if (get_scope_typeof(source_instruction->scope)) { |
| | 15412 | return ir_const_undef(ira, source_instruction, child_type); |
| | 15413 | } |
| | 15414 | |
| 15409 | ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value")); | 15415 | ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value")); |
| 15410 | return ira->codegen->invalid_inst_gen; | 15416 | return ira->codegen->invalid_inst_gen; |
| 15411 | } | 15417 | } |
| ... | @@ -19709,7 +19715,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19709,7 +19715,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19709 | if (modifier == CallModifierCompileTime) { | 19715 | if (modifier == CallModifierCompileTime) { |
| 19710 | // If we are evaluating an extern function in a TypeOf call, we can return an undefined value | 19716 | // If we are evaluating an extern function in a TypeOf call, we can return an undefined value |
| 19711 | // of its return type. | 19717 | // of its return type. |
| 19712 | if (fn_entry != nullptr && source_instr->scope->id == ScopeIdTypeOf && | 19718 | if (fn_entry != nullptr && get_scope_typeof(source_instr->scope) != nullptr && |
| 19713 | fn_proto_node->data.fn_proto.is_extern) { | 19719 | fn_proto_node->data.fn_proto.is_extern) { |
| 19714 | | 19720 | |
| 19715 | assert(fn_entry->body_node == nullptr); | 19721 | assert(fn_entry->body_node == nullptr); |
| ... | @@ -21842,6 +21848,11 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name | ... | @@ -21842,6 +21848,11 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 21842 | return ir_analyze_inferred_field_ptr(ira, field_name, source_instr, container_ptr, bare_type); | 21848 | return ir_analyze_inferred_field_ptr(ira, field_name, source_instr, container_ptr, bare_type); |
| 21843 | } | 21849 | } |
| 21844 | | 21850 | |
| | 21851 | // Tracks wether we should return an undefined value of the correct type. |
| | 21852 | // We do this if the container pointer is undefined and we are in a TypeOf call. |
| | 21853 | bool return_undef = container_ptr->value->special == ConstValSpecialUndef && \ |
| | 21854 | get_scope_typeof(source_instr->scope) != nullptr; |
| | 21855 | |
| 21845 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) | 21856 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 21846 | return ira->codegen->invalid_inst_gen; | 21857 | return ira->codegen->invalid_inst_gen; |
| 21847 | | 21858 | |
| ... | @@ -21849,6 +21860,12 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name | ... | @@ -21849,6 +21860,12 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 21849 | if (bare_type->id == ZigTypeIdStruct) { | 21860 | if (bare_type->id == ZigTypeIdStruct) { |
| 21850 | TypeStructField *field = find_struct_type_field(bare_type, field_name); | 21861 | TypeStructField *field = find_struct_type_field(bare_type, field_name); |
| 21851 | if (field != nullptr) { | 21862 | if (field != nullptr) { |
| | 21863 | if (return_undef) { |
| | 21864 | ZigType *field_ptr_type = get_pointer_to_type(ira->codegen, resolve_struct_field_type(ira->codegen, field), |
| | 21865 | container_ptr->value->type->data.pointer.is_const); |
| | 21866 | return ir_const_undef(ira, source_instr, field_ptr_type); |
| | 21867 | } |
| | 21868 | |
| 21852 | return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing); | 21869 | return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing); |
| 21853 | } else { | 21870 | } else { |
| 21854 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 21871 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |