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

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

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