interp: fix parsing of assign to dereferenced pointer

Fixes #969.
This commit is contained in:
Marc Vertes
2020-11-30 17:46:05 +01:00
committed by GitHub
parent b25ee3f809
commit 662d2a6afe
2 changed files with 4 additions and 0 deletions

View File

@@ -75,6 +75,9 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) {
case assignStmt, defineStmt:
a := n.anc
i := childPos(n) - a.nright
if i < 0 {
break
}
if len(a.child) > a.nright+a.nleft {
i--
}

View File

@@ -110,6 +110,7 @@ func TestEvalAssign(t *testing.T) {
{src: "f := int64(3.2)", err: "1:39: cannot convert expression of type float64 to type int64"},
{src: "g := 1; g <<= 8", res: "256"},
{src: "h := 1; h >>= 8", res: "0"},
{src: "i := 1; j := &i; (*j) = 2", res: "2"},
})
}