-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: implement conversion for interpreter function types
Interpreter function types are represented internally by the AST node of their definition. The conversion operation creates a new node with the type field pointing to the target type. Fixes #936.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
type T struct { | ||
v int | ||
} | ||
|
||
type comparator func(T, T) bool | ||
|
||
func sort(items []T, comp comparator) { | ||
println("in sort") | ||
} | ||
|
||
func compT(t0, t1 T) bool { return t0.v < t1.v } | ||
|
||
func main() { | ||
a := []T{} | ||
sort(a, comparator(compT)) | ||
} | ||
|
||
// Output: | ||
// in sort |
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