Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface with unexported method fails type assertion #1355

Closed
theclapp opened this issue Feb 13, 2022 · 0 comments · Fixed by #1393
Closed

Interface with unexported method fails type assertion #1355

theclapp opened this issue Feb 13, 2022 · 0 comments · Fixed by #1393
Labels
area/core bug Something isn't working
Milestone

Comments

@theclapp
Copy link
Contributor

The following program sample.go triggers an unexpected result

package main

import (
	"fmt"

	"github.com/traefik/yaegi/_test/p2"
)

func main() {
	var v *p2.T
	var i interface{}

	i = v
	if _, ok := i.(p2.I); ok {
		fmt.Printf("ok\n")
	} else {
		fmt.Printf("not ok\n")
	}
}

Expected result

$ go run ./sample.go
ok

Got

$ yaegi run ./sample.go
not ok

Yaegi Version

14acf61

Additional Notes

github.com/traefik/yaegi/_test/p2/p2.go is

package p2

type I interface {
	isI()
}

type T struct{}

func (t *T) isI() {}

This is similar to #1025.

@mvertes mvertes added bug Something isn't working area/core labels Apr 8, 2022
@mvertes mvertes added this to the v0.11.x milestone Apr 8, 2022
mvertes added a commit to mvertes/yaegi that referenced this issue May 3, 2022
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 traefik#1355.
mvertes added a commit that referenced this issue May 19, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants