-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add VarDecl support for struct-method call syntax
implements #3306
- Loading branch information
Showing
3 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |