mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
Sema: evaluate generic instantiations in fn decls capture scope
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.
This commit is contained in:
parent
1b79a42da0
commit
8bd94759bf
@ -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,
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user