master
1const builtin = @import("builtin");
2const expect = @import("std").testing.expect;
3
4fn get_foo() fn (*u8) usize {
5 comptime {
6 return struct {
7 fn func(ptr: *u8) usize {
8 return @intFromPtr(ptr);
9 }
10 }.func;
11 }
12}
13
14test "define a function in an anonymous struct in comptime" {
15 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
16
17 const foo = get_foo();
18 try expect(foo(@as(*u8, @ptrFromInt(12345))) == 12345);
19}