Skip to content

Commit

Permalink
interp: handle aliased string used as a slice
Browse files Browse the repository at this point in the history
Fixes #1002.
  • Loading branch information
mvertes authored Jan 14, 2021
1 parent 8a1f9ef commit 8ad14d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,13 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) {
wireChild(n)
t := n.child[0].typ
switch t.cat {
case aliasT, ptrT:
case aliasT:
if isString(t.val.TypeOf()) {
n.typ = sc.getType("byte")
break
}
fallthrough
case ptrT:
n.typ = t.val
if t.val.cat == valueT {
n.typ = &itype{cat: valueT, rtype: t.val.rtype.Elem()}
Expand Down
1 change: 1 addition & 0 deletions interp/interp_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ func TestEvalSliceExpression(t *testing.T) {
{src: `a := []int{0,1,2,3}[1::4]`, err: "1:49: 2nd index required in 3-index slice"},
{src: `a := []int{0,1,2,3}[1:3:]`, err: "1:51: 3rd index required in 3-index slice"},
{src: `a := []int{0,1,2}[3:1]`, err: "invalid index values, must be low <= high <= max"},
{pre: func() { eval(t, i, `type Str = string; var r Str = "truc"`) }, src: `r[1]`, res: "114"},
})
}

Expand Down

0 comments on commit 8ad14d8

Please sign in to comment.