fix: correct assign from function returning an interface value (#625)
This commit is contained in:
23
_test/interface37.go
Normal file
23
_test/interface37.go
Normal 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
|
||||||
@@ -678,7 +678,7 @@ func call(n *node) {
|
|||||||
switch {
|
switch {
|
||||||
case c.ident == "_":
|
case c.ident == "_":
|
||||||
// Skip assigning return value to blank var.
|
// 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)
|
rvalues[i] = genValueInterfaceValue(c)
|
||||||
default:
|
default:
|
||||||
rvalues[i] = genValue(c)
|
rvalues[i] = genValue(c)
|
||||||
|
|||||||
Reference in New Issue
Block a user