| ... | @@ -10104,19 +10104,12 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -10104,19 +10104,12 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 10104 | } | 10104 | } |
| 10105 | | 10105 | |
| 10106 | IrInstSrc *return_type; | 10106 | IrInstSrc *return_type; |
| 10107 | if (node->data.fn_proto.return_anytype_token == nullptr) { | 10107 | if (node->data.fn_proto.return_type == nullptr) { |
| 10108 | if (node->data.fn_proto.return_type == nullptr) { | 10108 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); |
| 10109 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); | | |
| 10110 | } else { | | |
| 10111 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); | | |
| 10112 | if (return_type == irb->codegen->invalid_inst_src) | | |
| 10113 | return irb->codegen->invalid_inst_src; | | |
| 10114 | } | | |
| 10115 | } else { | 10109 | } else { |
| 10116 | add_node_error(irb->codegen, node, | 10110 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); |
| 10117 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); | 10111 | if (return_type == irb->codegen->invalid_inst_src) |
| 10118 | return irb->codegen->invalid_inst_src; | 10112 | return irb->codegen->invalid_inst_src; |
| 10119 | //return_type = nullptr; | | |
| 10120 | } | 10113 | } |
| 10121 | | 10114 | |
| 10122 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); | 10115 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); |
| ... | @@ -14978,7 +14971,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou | ... | @@ -14978,7 +14971,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 14978 | | 14971 | |
| 14979 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) | 14972 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) |
| 14980 | return ira->codegen->invalid_inst_gen; | 14973 | return ira->codegen->invalid_inst_gen; |
| 14981 | | 14974 | |
| 14982 | size_t array_len = wanted_type->data.array.len; | 14975 | size_t array_len = wanted_type->data.array.len; |
| 14983 | size_t instr_field_count = actual_type->data.structure.src_field_count; | 14976 | size_t instr_field_count = actual_type->data.structure.src_field_count; |
| 14984 | assert(array_len == instr_field_count); | 14977 | assert(array_len == instr_field_count); |
| ... | @@ -20953,44 +20946,42 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -20953,44 +20946,42 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20953 | inst_fn_type_id.alignment = align_bytes; | 20946 | inst_fn_type_id.alignment = align_bytes; |
| 20954 | } | 20947 | } |
| 20955 | | 20948 | |
| 20956 | if (fn_proto_node->data.fn_proto.return_anytype_token == nullptr) { | 20949 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 20957 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; | 20950 | ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node); |
| 20958 | ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node); | 20951 | if (type_is_invalid(specified_return_type)) |
| 20959 | if (type_is_invalid(specified_return_type)) | 20952 | return ira->codegen->invalid_inst_gen; |
| 20960 | return ira->codegen->invalid_inst_gen; | | |
| 20961 | | | |
| 20962 | if(!is_valid_return_type(specified_return_type)){ | | |
| 20963 | ErrorMsg *msg = ir_add_error(ira, source_instr, | | |
| 20964 | buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name))); | | |
| 20965 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here")); | | |
| 20966 | | 20953 | |
| 20967 | Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name); | 20954 | if(!is_valid_return_type(specified_return_type)){ |
| 20968 | if (tld != nullptr) { | 20955 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 20969 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("type declared here")); | 20956 | buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name))); |
| 20970 | } | 20957 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here")); |
| 20971 | return ira->codegen->invalid_inst_gen; | | |
| 20972 | } | | |
| 20973 | | 20958 | |
| 20974 | if (fn_proto_node->data.fn_proto.auto_err_set) { | 20959 | Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name); |
| 20975 | ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); | 20960 | if (tld != nullptr) { |
| 20976 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) | 20961 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("type declared here")); |
| 20977 | return ira->codegen->invalid_inst_gen; | | |
| 20978 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); | | |
| 20979 | } else { | | |
| 20980 | inst_fn_type_id.return_type = specified_return_type; | | |
| 20981 | } | 20962 | } |
| | 20963 | return ira->codegen->invalid_inst_gen; |
| | 20964 | } |
| 20982 | | 20965 | |
| 20983 | switch (type_requires_comptime(ira->codegen, specified_return_type)) { | 20966 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 20984 | case ReqCompTimeYes: | 20967 | ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); |
| 20985 | // Throw out our work and call the function as if it were comptime. | 20968 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 20986 | return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr, | | |
| 20987 | first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin, | | |
| 20988 | args_ptr, args_len, ret_ptr, call_result_loc); | | |
| 20989 | case ReqCompTimeInvalid: | | |
| 20990 | return ira->codegen->invalid_inst_gen; | 20969 | return ira->codegen->invalid_inst_gen; |
| 20991 | case ReqCompTimeNo: | 20970 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 20992 | break; | 20971 | } else { |
| 20993 | } | 20972 | inst_fn_type_id.return_type = specified_return_type; |
| | 20973 | } |
| | 20974 | |
| | 20975 | switch (type_requires_comptime(ira->codegen, specified_return_type)) { |
| | 20976 | case ReqCompTimeYes: |
| | 20977 | // Throw out our work and call the function as if it were comptime. |
| | 20978 | return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr, |
| | 20979 | first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin, |
| | 20980 | args_ptr, args_len, ret_ptr, call_result_loc); |
| | 20981 | case ReqCompTimeInvalid: |
| | 20982 | return ira->codegen->invalid_inst_gen; |
| | 20983 | case ReqCompTimeNo: |
| | 20984 | break; |
| 20994 | } | 20985 | } |
| 20995 | | 20986 | |
| 20996 | auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn); | 20987 | auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn); |