aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2024-02-18 01:06:13 +0100
committerAndrew Kelley <andrew@ziglang.org>2024-02-26 16:50:00 -0800
commit8bd94759bf48c3247d4de14806ff2f510cb36591 (patch)
tree4f761c514223e41130806361ebec476c174f4095 /test
parent1b79a42da096fcdeac22b56f17f82b0c7ec22a9b (diff)
downloadzig-8bd94759bf48c3247d4de14806ff2f510cb36591.tar.gz
zig-8bd94759bf48c3247d4de14806ff2f510cb36591.zip
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.
Diffstat (limited to 'test')
-rw-r--r--test/behavior/generics.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig
index f50e6bf7f4..aca76ece58 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]);
+}