aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/fn_in_struct_in_comptime.zig
blob: 0acadbc5ea9c95d494f436b49634e00f43c80086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const builtin = @import("builtin");
const expect = @import("std").testing.expect;

fn get_foo() fn (*u8) usize {
    comptime {
        return struct {
            fn func(ptr: *u8) usize {
                var u = @intFromPtr(ptr);
                return u;
            }
        }.func;
    }
}

test "define a function in an anonymous struct in comptime" {
    const foo = get_foo();
    try expect(foo(@as(*u8, @ptrFromInt(12345))) == 12345);
}