Skip to content

Commit 1c09e5e

Browse files
authored
Fix error position reporting in multiline script (#827)
1 parent bbcbc53 commit 1c09e5e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

expr_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,17 @@ func TestEval_exposed_error(t *testing.T) {
17571757
require.Equal(t, 1, fileError.Line)
17581758
}
17591759

1760+
func TestCompile_exposed_error_with_multiline_script(t *testing.T) {
1761+
_, err := expr.Compile("{\n\ta: 1,\n\tb: #,\n\tc: 3,\n}")
1762+
require.Error(t, err)
1763+
1764+
fileError, ok := err.(*file.Error)
1765+
require.True(t, ok, "error should be of type *file.Error")
1766+
require.Equal(t, "unexpected token Operator(\"#\") (3:5)\n | b: #,\n | ....^", fileError.Error())
1767+
require.Equal(t, 4, fileError.Column)
1768+
require.Equal(t, 3, fileError.Line)
1769+
}
1770+
17601771
func TestIssue105(t *testing.T) {
17611772
type A struct {
17621773
Field string

file/error.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ func (e *Error) Bind(source Source) *Error {
3131
break
3232
}
3333
if r == '\n' {
34-
lineStart = i
34+
lineStart = i + 1
3535
e.Line++
3636
e.Column = 0
37+
} else {
38+
e.Column++
3739
}
3840
runeCount++
39-
e.Column++
4041
}
4142

4243
lineEnd := lineStart + strings.IndexByte(src[lineStart:], '\n')

0 commit comments

Comments
 (0)