diff --git a/src/Sema.zig b/src/Sema.zig index 741c4e2fbaa387b03f2a357d107768a0079e3851..e0a8d1fe00e46b827453cfd763b3ecf19f97d394 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -7951,7 +7951,7 @@ fn instantiateGenericCall( .sema = &child_sema, .src_decl = generic_owner_func.owner_decl, .namespace = namespace_index, - .wip_capture_scope = try mod.createCaptureScope(sema.owner_decl.src_scope), + .wip_capture_scope = try mod.createCaptureScope(fn_owner_decl.src_scope), .instructions = .{}, .inlining = null, .is_comptime = true, diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index f50e6bf7f486189aba9bb6c0c8d0759c62473a20..aca76ece583803c05714daf54a8c15ee2033eb0e 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -558,3 +558,19 @@ test "call generic function with from function called by the generic function" { ArgSerializer.serializeCommand(GET{ .key = "banana" }); } + +fn StructCapture(comptime T: type) type { + return struct { + pub fn foo(comptime x: usize) struct { T } { + return .{x}; + } + }; +} + +test "call generic function that uses capture from function declaration's scope" { + if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; + + const S = StructCapture(f64); + const s = S.foo(123); + try expectEqual(123.0, s[0]); +}