| author | |
| committer | |
| log | d09d61be979fc97233bd53d9d082a86e4dcd9779 |
| tree | 502e0476e43e1a8ea0e0dd9e48e9fb8f76d1dd7c |
| parent | d410693dadfe791e616e78239fa0cec707b95cfa |
| parent | 282437c7538e3e70ce06cfee7affe976de28a780 |
| signature |
Stage2 fixes3 files changed, 47 insertions(+), 10 deletions(-)
src/Sema.zig+6-3| ... | ... | @@ -2976,7 +2976,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2976 | 2976 | |
| 2977 | 2977 | // Even though we reuse the constant instruction, we still remove it from the |
| 2978 | 2978 | // block so that codegen does not see it. |
| 2979 | block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3); | |
| 2979 | block.instructions.shrinkRetainingCapacity(search_index); | |
| 2980 | 2980 | sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl_index); |
| 2981 | 2981 | // if bitcast ty ref needs to be made const, make_ptr_const |
| 2982 | 2982 | // ZIR handles it later, so we can just use the ty ref here. |
| ... | ... | @@ -13011,10 +13011,13 @@ fn analyzeRet( |
| 13011 | 13011 | const backend_supports_error_return_tracing = |
| 13012 | 13012 | sema.mod.comp.bin_file.options.use_llvm; |
| 13013 | 13013 | |
| 13014 | if ((sema.fn_ret_ty.zigTypeTag() == .ErrorSet or sema.typeOf(uncasted_operand).zigTypeTag() == .ErrorUnion) and | |
| 13014 | if (sema.fn_ret_ty.isError() and | |
| 13015 | 13015 | sema.mod.comp.bin_file.options.error_return_tracing and |
| 13016 | 13016 | backend_supports_error_return_tracing) |
| 13017 | { | |
| 13017 | ret_err: { | |
| 13018 | if (try sema.resolveMaybeUndefVal(block, src, operand)) |ret_val| { | |
| 13019 | if (ret_val.tag() != .@"error") break :ret_err; | |
| 13020 | } | |
| 13018 | 13021 | const return_err_fn = try sema.getBuiltin(block, src, "returnError"); |
| 13019 | 13022 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 13020 | 13023 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
src/type.zig+13-7| ... | ... | @@ -640,16 +640,16 @@ pub const Type = extern union { |
| 640 | 640 | if (!eql(a_info.return_type, b_info.return_type, mod)) |
| 641 | 641 | return false; |
| 642 | 642 | |
| 643 | if (a_info.cc != b_info.cc) | |
| 643 | if (a_info.is_var_args != b_info.is_var_args) | |
| 644 | 644 | return false; |
| 645 | 645 | |
| 646 | if (a_info.alignment != b_info.alignment) | |
| 646 | if (a_info.is_generic != b_info.is_generic) | |
| 647 | 647 | return false; |
| 648 | 648 | |
| 649 | if (a_info.is_var_args != b_info.is_var_args) | |
| 649 | if (!a_info.cc_is_generic and a_info.cc != b_info.cc) | |
| 650 | 650 | return false; |
| 651 | 651 | |
| 652 | if (a_info.is_generic != b_info.is_generic) | |
| 652 | if (!a_info.align_is_generic and a_info.alignment != b_info.alignment) | |
| 653 | 653 | return false; |
| 654 | 654 | |
| 655 | 655 | if (a_info.param_types.len != b_info.param_types.len) |
| ... | ... | @@ -1036,9 +1036,15 @@ pub const Type = extern union { |
| 1036 | 1036 | std.hash.autoHash(hasher, std.builtin.TypeId.Fn); |
| 1037 | 1037 | |
| 1038 | 1038 | const fn_info = ty.fnInfo(); |
| 1039 | hashWithHasher(fn_info.return_type, hasher, mod); | |
| 1040 | std.hash.autoHash(hasher, fn_info.alignment); | |
| 1041 | std.hash.autoHash(hasher, fn_info.cc); | |
| 1039 | if (fn_info.return_type.tag() != .generic_poison) { | |
| 1040 | hashWithHasher(fn_info.return_type, hasher, mod); | |
| 1041 | } | |
| 1042 | if (!fn_info.align_is_generic) { | |
| 1043 | std.hash.autoHash(hasher, fn_info.alignment); | |
| 1044 | } | |
| 1045 | if (!fn_info.cc_is_generic) { | |
| 1046 | std.hash.autoHash(hasher, fn_info.cc); | |
| 1047 | } | |
| 1042 | 1048 | std.hash.autoHash(hasher, fn_info.is_var_args); |
| 1043 | 1049 | std.hash.autoHash(hasher, fn_info.is_generic); |
| 1044 | 1050 |
test/behavior/basic.zig+28| ... | ... | @@ -977,3 +977,31 @@ test "weird array and tuple initializations" { |
| 977 | 977 | .b = if (a) .{ .e = .a } else .{ .e = .b }, |
| 978 | 978 | }; |
| 979 | 979 | } |
| 980 | ||
| 981 | test "array type comes from generic function" { | |
| 982 | const S = struct { | |
| 983 | fn A() type { | |
| 984 | return struct { a: u8 = 0 }; | |
| 985 | } | |
| 986 | }; | |
| 987 | const args = [_]S.A(){.{}}; | |
| 988 | _ = args; | |
| 989 | } | |
| 990 | ||
| 991 | test "generic function uses return type of other generic function" { | |
| 992 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 993 | ||
| 994 | const S = struct { | |
| 995 | fn call( | |
| 996 | f: anytype, | |
| 997 | args: anytype, | |
| 998 | ) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) { | |
| 999 | return @call(.{}, f, args); | |
| 1000 | } | |
| 1001 | ||
| 1002 | fn func(arg: anytype) @TypeOf(arg) { | |
| 1003 | return arg; | |
| 1004 | } | |
| 1005 | }; | |
| 1006 | try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1); | |
| 1007 | } |