diff options
| author | Michael Dusan <michael.dusan@gmail.com> | 2019-09-24 17:53:05 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-09-24 19:24:48 -0400 |
| commit | 9983501ff2cccf828bb357dddefb21e36813046d (patch) | |
| tree | 4e46409e9a0fc1ba3cf0abbeb831c74b1107498e /test | |
| parent | 56b1818beb0e6acce60ff399556af257acc77983 (diff) | |
| download | zig-9983501ff2cccf828bb357dddefb21e36813046d.tar.gz zig-9983501ff2cccf828bb357dddefb21e36813046d.zip | |
add VarDecl support for struct-method call syntax
implements #3306
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage1/behavior.zig | 1 | ||||
| -rw-r--r-- | test/stage1/behavior/fn_delegation.zig | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 9b7f4305c2..569e6e2b51 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -58,6 +58,7 @@ comptime { _ = @import("behavior/floatop.zig"); _ = @import("behavior/fn.zig"); _ = @import("behavior/fn_in_struct_in_comptime.zig"); + _ = @import("behavior/fn_delegation.zig"); _ = @import("behavior/for.zig"); _ = @import("behavior/generics.zig"); _ = @import("behavior/hasdecl.zig"); diff --git a/test/stage1/behavior/fn_delegation.zig b/test/stage1/behavior/fn_delegation.zig new file mode 100644 index 0000000000..57006805c8 --- /dev/null +++ b/test/stage1/behavior/fn_delegation.zig @@ -0,0 +1,39 @@ +const expect = @import("std").testing.expect; + +const Foo = struct { + a: u64 = 10, + + fn one(self: Foo) u64 { + return self.a + 1; + } + + const two = __two; + + fn __two(self: Foo) u64 { + return self.a + 2; + } + + const three = __three; + + const four = custom(Foo, 4); +}; + +fn __three(self: Foo) u64 { + return self.a + 3; +} + +fn custom(comptime T: type, comptime num: u64) fn (T) u64 { + return struct { + fn function(self: T) u64 { + return self.a + num; + } + }.function; +} + +test "fn delegation" { + const foo = Foo{}; + expect(foo.one() == 11); + expect(foo.two() == 12); + expect(foo.three() == 13); + expect(foo.four() == 14); +} |
