fix: correct type assertion for bin func types (#588)

This commit is contained in:
Marc Vertes
2020-04-20 23:01:01 +02:00
committed by GitHub
parent 5e142fdedd
commit 3ed4ec3f6f
2 changed files with 22 additions and 1 deletions

16
_test/type21.go Normal file
View File

@@ -0,0 +1,16 @@
package main
import (
"reflect"
"time"
)
func main() {
t := time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC)
v := reflect.ValueOf(t.String)
f := v.Interface().(func() string)
println(f())
}
// Output:
// 2009-11-10 23:04:05 +0000 UTC

View File

@@ -1503,7 +1503,12 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
}
}
if n.anc.action != aAssignX {
n.typ = n.child[1].typ
if n.child[0].typ.cat == valueT {
// Avoid special wrapping of interfaces and func types.
n.typ = &itype{cat: valueT, rtype: n.child[1].typ.TypeOf()}
} else {
n.typ = n.child[1].typ
}
n.findex = sc.add(n.typ)
}
} else {