ability to refer to member function directly

See #14
This commit is contained in:
Andrew Kelley
2016-01-28 16:45:17 -07:00
parent 13220ccb51
commit bb4f783528
3 changed files with 41 additions and 8 deletions

View File

@@ -1386,9 +1386,27 @@ pub fn main(args: [][]u8) -> %void {
if (*ptr != 6) {
%%stdout.printf("BAD\n");
}
%%stdout.printf("OK\n");
free(ptr);
%%stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("store member function in variable", R"SOURCE(
import "std.zig";
struct Foo {
x: i32,
fn member(foo: Foo) -> i32 { foo.x }
}
pub fn main(args: [][]u8) -> %void {
const instance = Foo { .x = 1234, };
const member_fn = Foo.member;
const result = member_fn(instance);
if (result != 1234) {
%%stdout.printf("BAD\n");
}
%%stdout.printf("OK\n");
}
)SOURCE", "OK\n");
}