interp: fix derivation of type of slice expression of binary object

Fixes #1328.
This commit is contained in:
Marc Vertes
2021-12-20 15:46:05 +01:00
committed by GitHub
parent 2af660cb1f
commit 2819b4167b
2 changed files with 24 additions and 0 deletions

16
_test/issue-1328.go Normal file
View File

@@ -0,0 +1,16 @@
package main
import (
"crypto/sha1"
"encoding/hex"
)
func main() {
script := "hello"
sumRaw := sha1.Sum([]byte(script))
sum := hex.EncodeToString(sumRaw[:])
println(sum)
}
// Output:
// aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

View File

@@ -854,6 +854,14 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype,
if err != nil {
return nil, err
}
if t.cat == valueT {
switch t.rtype.Kind() {
case reflect.Array, reflect.Ptr:
t = valueTOf(reflect.SliceOf(t.rtype.Elem()), withScope(sc))
}
break
}
if t.cat == ptrT {
t = t.val
}