Skip to content

Commit

Permalink
Fixed panic when converting index ranges to string
Browse files Browse the repository at this point in the history
  • Loading branch information
odino committed Apr 4, 2020
1 parent 47455ff commit 05866fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,18 @@ func (ie *IndexExpression) String() string {
out.WriteString("[")

if ie.IsRange {
out.WriteString(ie.Index.String() + ":" + ie.End.String())
start := ""

if ie.Index != nil {
start = ie.Index.String()
}

end := ""

if ie.End != nil {
end = ie.End.String()
}
out.WriteString(start + ":" + end)
} else {
out.WriteString(ie.Index.String())
}
Expand Down
2 changes: 2 additions & 0 deletions evaluator/builtin_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ func TestStr(t *testing.T) {
{`1.str()`, "1"},
{`[1].str()`, "[1]"},
{`{"a": 10}.str()`, `{"a": 10}`},
{`f() {a[3:]}.str()`, `f() {(a[3:])}`},
{`f() {a[:3]}.str()`, `f() {(a[0:3])}`},
}

testBuiltinFunction(tests, t)
Expand Down

0 comments on commit 05866fb

Please sign in to comment.