fix: correct handling of methods on binary interface types (#218)
This commit is contained in:
committed by
Ludovic Fernandez
parent
686769fa84
commit
f5353e55c8
16
_test/bin1.go
Normal file
16
_test/bin1.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
d := sha1.New()
|
||||
d.Write([]byte("password"))
|
||||
a := d.Sum(nil)
|
||||
fmt.Println(a)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// [91 170 97 228 201 185 63 63 6 130 37 11 108 248 51 27 126 230 143 216]
|
||||
@@ -1042,8 +1042,8 @@ func (interp *Interpreter) Cfg(root *Node) ([]*Node, error) {
|
||||
case ok:
|
||||
n.val = method.Index
|
||||
n.gen = getIndexBinMethod
|
||||
n.typ = &Type{cat: ValueT, rtype: method.Type}
|
||||
n.recv = &Receiver{node: n.child[0]}
|
||||
n.typ = &Type{cat: ValueT, rtype: method.Type}
|
||||
case n.typ.rtype.Kind() == reflect.Ptr:
|
||||
if field, ok := n.typ.rtype.Elem().FieldByName(n.child[1].ident); ok {
|
||||
n.typ = &Type{cat: ValueT, rtype: field.Type}
|
||||
|
||||
@@ -727,8 +727,9 @@ func callBin(n *Node) {
|
||||
if funcType.IsVariadic() {
|
||||
variadic = funcType.NumIn() - 1
|
||||
}
|
||||
// method signature obtained from reflect.Type include receiver as 1st arg, except for interface types
|
||||
receiverOffset := 0
|
||||
if n.child[0].recv != nil {
|
||||
if recv := n.child[0].recv; recv != nil && recv.node.typ.TypeOf().Kind() != reflect.Interface {
|
||||
receiverOffset = 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user