Skip to content

Commit

Permalink
interp: fix derivation of type of slice expression of binary object
Browse files Browse the repository at this point in the history
Fixes #1328.
  • Loading branch information
mvertes committed Dec 20, 2021
1 parent 2af660c commit 2819b41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions _test/issue-1328.go
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions interp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2819b41

Please sign in to comment.