authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-09 15:32:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-09 15:35:13-07:00
log83bb3d1ad692127cd51c101b6a01fc853ab72990
treeb7a8c22eeb3dcbf252dec787b9437b9aee117dbb
parent2aa4a32097392c869fe2ef58f372a960c0268859

Sema: fix generic fn instantiation with anytype

When the anytype parameter had only one-possible-value (e.g. `void`), it would create a mismatch in the function type and the function call. Now the function type and the callsite both omit the one-possible-value anytype parameter in instantiated generic functions.

3 files changed, 9 insertions(+), 2 deletions(-)

src/Sema.zig+3
...@@ -6158,6 +6158,9 @@ fn zirParamAnytype(...@@ -6158,6 +6158,9 @@ fn zirParamAnytype(
6158 // function type of the function instruction in this block.6158 // function type of the function instruction in this block.
6159 return;6159 return;
6160 }6160 }
6161 if (null != try sema.typeHasOnePossibleValue(block, src, param_ty)) {
6162 return;
6163 }
6161 // The map is already populated but we do need to add a runtime parameter.6164 // The map is already populated but we do need to add a runtime parameter.
6162 try block.params.append(sema.gpa, .{6165 try block.params.append(sema.gpa, .{
6163 .ty = param_ty,6166 .ty = param_ty,
test/behavior/translate_c_macros.zig+1-1
...@@ -39,7 +39,7 @@ test "reference to a struct type" {...@@ -39,7 +39,7 @@ test "reference to a struct type" {
39}39}
4040
41test "cast negative integer to pointer" {41test "cast negative integer to pointer" {
42 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO42 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
4343
44 try expectEqual(@intToPtr(?*anyopaque, @bitCast(usize, @as(isize, -1))), h.MAP_FAILED);44 try expectEqual(@intToPtr(?*anyopaque, @bitCast(usize, @as(isize, -1))), h.MAP_FAILED);
45}45}
test/behavior/tuple.zig+5-1
...@@ -50,7 +50,11 @@ test "tuple multiplication" {...@@ -50,7 +50,11 @@ test "tuple multiplication" {
50}50}
5151
52test "more tuple concatenation" {52test "more tuple concatenation" {
53 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO53 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
54 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
55 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
56 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
57 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
5458
55 const T = struct {59 const T = struct {
56 fn consume_tuple(tuple: anytype, len: usize) !void {60 fn consume_tuple(tuple: anytype, len: usize) !void {