-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: fix closure in a struct field
Functions in a struct fields are always wrapped (as potentially used by the runtime), so generate a function wrapper also for closure when assigned to a struct field. When such a function is called from the interpreter, ensure that interface arguments are also wrapped so method and receiver resolution can be performed. Fixes partially #1043.
- Loading branch information
Showing
5 changed files
with
70 additions
and
10 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,26 @@ | ||
package main | ||
|
||
type I interface{ Hello() } | ||
|
||
type T struct{ Name string } | ||
|
||
func (t *T) Hello() { println("Hello", t.Name) } | ||
|
||
type FT func(i I) | ||
|
||
type ST struct{ Handler FT } | ||
|
||
func newF() FT { | ||
return func(i I) { | ||
i.Hello() | ||
} | ||
} | ||
|
||
func main() { | ||
st := &ST{} | ||
st.Handler = newF() | ||
st.Handler(&T{"test"}) | ||
} | ||
|
||
// Output: | ||
// Hello test |
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
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