提交 e45443b3 编写于 作者: A aarzilli

proc/eval: Return an error when slicing a map over its length

Fixes #288
上级 7a36967b
......@@ -327,6 +327,10 @@ func (scope *EvalScope) evalReslice(node *ast.SliceExpr) (*Variable, error) {
return nil, fmt.Errorf("second slice argument must be empty for maps")
}
xev.mapSkip += int(low)
xev.loadValue()
if xev.Unreadable != nil {
return nil, xev.Unreadable
}
return xev, nil
default:
return nil, fmt.Errorf("can not slice \"%s\" (type %s)", exprToString(node.X), xev.DwarfType.String())
......
......@@ -1113,6 +1113,7 @@ func (v *Variable) loadMap(recurseLevel int) {
for skip := 0; skip < v.mapSkip; skip++ {
if ok := it.next(); !ok {
v.Unreadable = fmt.Errorf("map index out of bounds")
return
}
}
......
......@@ -396,6 +396,7 @@ func TestEvalExpression(t *testing.T) {
{"m2[*p1].B", false, "11", "", "int", nil},
{"m3[as1]", false, "42", "", "int", nil},
{"mnil[\"Malone\"]", false, "", "", "", fmt.Errorf("key not found")},
{"m1[80:]", false, "", "", "", fmt.Errorf("map index out of bounds")},
// combined expressions
{"c1.pb.a.A", true, "1", "", "int", nil},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册