fix: correct assign from function returning an interface value (#625)

This commit is contained in:
Marc Vertes
2020-05-05 13:54:36 +02:00
committed by GitHub
parent 7eac6955b3
commit 7fab75fbe4
2 changed files with 24 additions and 1 deletions

23
_test/interface37.go Normal file
View File

@@ -0,0 +1,23 @@
package main
type I interface {
A() string
B() string
}
type s struct{}
func NewS() (I, error) {
return &s{}, nil
}
func (c *s) A() string { return "a" }
func (c *s) B() string { return "b" }
func main() {
s, _ := NewS()
println(s.A())
}
// Output:
// a

View File

@@ -678,7 +678,7 @@ func call(n *node) {
switch {
case c.ident == "_":
// Skip assigning return value to blank var.
case c.typ.cat == interfaceT:
case c.typ.cat == interfaceT && rtypes[i].cat != interfaceT:
rvalues[i] = genValueInterfaceValue(c)
default:
rvalues[i] = genValue(c)