diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-05-31 15:19:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-31 15:19:25 -0400 |
| commit | d09d61be979fc97233bd53d9d082a86e4dcd9779 (patch) | |
| tree | 502e0476e43e1a8ea0e0dd9e48e9fb8f76d1dd7c | |
| parent | d410693dadfe791e616e78239fa0cec707b95cfa (diff) | |
| parent | 282437c7538e3e70ce06cfee7affe976de28a780 (diff) | |
| download | zig-d09d61be979fc97233bd53d9d082a86e4dcd9779.tar.gz zig-d09d61be979fc97233bd53d9d082a86e4dcd9779.zip | |
Merge pull request #11762 from Vexu/stage2
Stage2 fixes
| -rw-r--r-- | src/Sema.zig | 9 | ||||
| -rw-r--r-- | src/type.zig | 20 | ||||
| -rw-r--r-- | test/behavior/basic.zig | 28 |
3 files changed, 47 insertions, 10 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 505810a158..d4c49973a1 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2976,7 +2976,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com // Even though we reuse the constant instruction, we still remove it from the // block so that codegen does not see it. - block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3); + block.instructions.shrinkRetainingCapacity(search_index); sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl_index); // if bitcast ty ref needs to be made const, make_ptr_const // ZIR handles it later, so we can just use the ty ref here. @@ -13011,10 +13011,13 @@ fn analyzeRet( const backend_supports_error_return_tracing = sema.mod.comp.bin_file.options.use_llvm; - if ((sema.fn_ret_ty.zigTypeTag() == .ErrorSet or sema.typeOf(uncasted_operand).zigTypeTag() == .ErrorUnion) and + if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and backend_supports_error_return_tracing) - { + ret_err: { + if (try sema.resolveMaybeUndefVal(block, src, operand)) |ret_val| { + if (ret_val.tag() != .@"error") break :ret_err; + } const return_err_fn = try sema.getBuiltin(block, src, "returnError"); const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); diff --git a/src/type.zig b/src/type.zig index ebb8bfd7c3..9a072fa911 100644 --- a/src/type.zig +++ b/src/type.zig @@ -640,16 +640,16 @@ pub const Type = extern union { if (!eql(a_info.return_type, b_info.return_type, mod)) return false; - if (a_info.cc != b_info.cc) + if (a_info.is_var_args != b_info.is_var_args) return false; - if (a_info.alignment != b_info.alignment) + if (a_info.is_generic != b_info.is_generic) return false; - if (a_info.is_var_args != b_info.is_var_args) + if (!a_info.cc_is_generic and a_info.cc != b_info.cc) return false; - if (a_info.is_generic != b_info.is_generic) + if (!a_info.align_is_generic and a_info.alignment != b_info.alignment) return false; if (a_info.param_types.len != b_info.param_types.len) @@ -1036,9 +1036,15 @@ pub const Type = extern union { std.hash.autoHash(hasher, std.builtin.TypeId.Fn); const fn_info = ty.fnInfo(); - hashWithHasher(fn_info.return_type, hasher, mod); - std.hash.autoHash(hasher, fn_info.alignment); - std.hash.autoHash(hasher, fn_info.cc); + if (fn_info.return_type.tag() != .generic_poison) { + hashWithHasher(fn_info.return_type, hasher, mod); + } + if (!fn_info.align_is_generic) { + std.hash.autoHash(hasher, fn_info.alignment); + } + if (!fn_info.cc_is_generic) { + std.hash.autoHash(hasher, fn_info.cc); + } std.hash.autoHash(hasher, fn_info.is_var_args); std.hash.autoHash(hasher, fn_info.is_generic); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index e887a1d4b6..32df664bae 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -977,3 +977,31 @@ test "weird array and tuple initializations" { .b = if (a) .{ .e = .a } else .{ .e = .b }, }; } + +test "array type comes from generic function" { + const S = struct { + fn A() type { + return struct { a: u8 = 0 }; + } + }; + const args = [_]S.A(){.{}}; + _ = args; +} + +test "generic function uses return type of other generic function" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + + const S = struct { + fn call( + f: anytype, + args: anytype, + ) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) { + return @call(.{}, f, args); + } + + fn func(arg: anytype) @TypeOf(arg) { + return arg; + } + }; + try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1); +} |
