-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make interpreter methods discoverable by runtime
When generating an interface wrapper, lookup existing wrappers by method to get the one with the biggest set of methods implemented by interpreter. A string method is also added to wrappers, in order to provide a string representation of the interpreter value rather than the wrapper itself (at least for %s and %v verbs). This allows the runtime to pickup an interpreter method automatically even if the conversion to the interface is not specified in the script. As in Go spec, it is enough for the type to implement the required methods. A current limitation is that only single wrappers can be instantiated, not allowing to compose interfaces. This limitation can be removed when the Go reflect issue golang/go#15924 is fixed. Fixes #435.
- Loading branch information
Showing
181 changed files
with
2,040 additions
and
43 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,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
type Foo int | ||
|
||
func (f Foo) String() string { | ||
return "foo-" + strconv.Itoa(int(f)) | ||
} | ||
|
||
func print1(arg interface{}) { | ||
fmt.Println(arg) | ||
} | ||
|
||
func main() { | ||
var arg Foo = 3 | ||
var f = print1 | ||
f(arg) | ||
} | ||
|
||
// Output: | ||
// foo-3 |
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
Oops, something went wrong.