2019-02-08 23:18:47 +00:00
|
|
|
const expect = @import("std").testing.expect;
|
2018-05-03 02:43:07 +01:00
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
fn get_foo() fn (*u8) usize {
|
2018-05-03 02:43:07 +01:00
|
|
|
comptime {
|
2018-11-13 13:08:37 +00:00
|
|
|
return struct {
|
2018-05-31 15:56:59 +01:00
|
|
|
fn func(ptr: *u8) usize {
|
2018-05-03 02:43:07 +01:00
|
|
|
var u = @ptrToInt(ptr);
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
}.func;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test "define a function in an anonymous struct in comptime" {
|
|
|
|
const foo = get_foo();
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(foo(@intToPtr(*u8, 12345)) == 12345);
|
2018-05-03 02:43:07 +01:00
|
|
|
}
|