| author | |
| committer | |
| log | 8bd94759bf48c3247d4de14806ff2f510cb36591 |
| tree | 4f761c514223e41130806361ebec476c174f4095 |
| parent | 1b79a42da096fcdeac22b56f17f82b0c7ec22a9b |
The generic call `S.foo()` was evaluated with the
capture scope of the owner decl (i.e the `test` block), when it should
use the capture scope of the function declaration.2 files changed, 17 insertions(+), 1 deletions(-)
src/Sema.zig+1-1| ... | @@ -7951,7 +7951,7 @@ fn instantiateGenericCall( | ... | @@ -7951,7 +7951,7 @@ fn instantiateGenericCall( |
| 7951 | .sema = &child_sema, | 7951 | .sema = &child_sema, |
| 7952 | .src_decl = generic_owner_func.owner_decl, | 7952 | .src_decl = generic_owner_func.owner_decl, |
| 7953 | .namespace = namespace_index, | 7953 | .namespace = namespace_index, |
| 7954 | .wip_capture_scope = try mod.createCaptureScope(sema.owner_decl.src_scope), | 7954 | .wip_capture_scope = try mod.createCaptureScope(fn_owner_decl.src_scope), |
| 7955 | .instructions = .{}, | 7955 | .instructions = .{}, |
| 7956 | .inlining = null, | 7956 | .inlining = null, |
| 7957 | .is_comptime = true, | 7957 | .is_comptime = true, |
test/behavior/generics.zig+16| ... | @@ -558,3 +558,19 @@ test "call generic function with from function called by the generic function" { | ... | @@ -558,3 +558,19 @@ test "call generic function with from function called by the generic function" { |
| 558 | 558 | ||
| 559 | ArgSerializer.serializeCommand(GET{ .key = "banana" }); | 559 | ArgSerializer.serializeCommand(GET{ .key = "banana" }); |
| 560 | } | 560 | } |
| 561 | |||
| 562 | fn StructCapture(comptime T: type) type { | ||
| 563 | return struct { | ||
| 564 | pub fn foo(comptime x: usize) struct { T } { | ||
| 565 | return .{x}; | ||
| 566 | } | ||
| 567 | }; | ||
| 568 | } | ||
| 569 | |||
| 570 | test "call generic function that uses capture from function declaration's scope" { | ||
| 571 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; | ||
| 572 | |||
| 573 | const S = StructCapture(f64); | ||
| 574 | const s = S.foo(123); | ||
| 575 | try expectEqual(123.0, s[0]); | ||
| 576 | } |