-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: improve handling of empty interface values (#1393)
At variable, function parameter, slice, map or field element assign, if the destination type is an empty interface, the value was never wrapped into a valueInterface (to preserve type mutability in case of re-assign). Now we wrap it in a valueInterface if the source type has a non empty set of methods, to allow a future use as a non empty interface. There are still corner cases, but it extends notably the support of interfaces within the interpreter. Fixes #1355.
- Loading branch information
Showing
4 changed files
with
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import "github.com/traefik/yaegi/_test/p2" | ||
|
||
func f(i interface{}) { | ||
_, ok := i.(p2.I) | ||
println("ok:", ok) | ||
} | ||
|
||
func main() { | ||
var v *p2.T | ||
var i interface{} | ||
|
||
i = v | ||
_, ok := i.(p2.I) | ||
println("ok:", ok) | ||
f(v) | ||
} | ||
|
||
// Output: | ||
// ok: true | ||
// ok: true |
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,9 @@ | ||
package p2 | ||
|
||
type I interface { | ||
isI() | ||
} | ||
|
||
type T struct{} | ||
|
||
func (t *T) isI() {} |
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