Skip to content

Commit

Permalink
syntax: report start-of-token pos for parsePrimary errors (#533)
Browse files Browse the repository at this point in the history
(Conceivably other places need a similar treament, but they
all seemed benign or marginal.)

Fixes #352
  • Loading branch information
adonovan committed Mar 29, 2024
1 parent ee8ed14 commit e6e8e7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion syntax/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,9 @@ func (p *parser) parsePrimary() Expr {
X: x,
}
}
p.in.errorf(p.in.pos, "got %#v, want primary expression", p.tok)

// Report start pos of final token as it may be a NEWLINE (#532).
p.in.errorf(p.tokval.pos, "got %#v, want primary expression", p.tok)
panic("unreachable")
}

Expand Down
8 changes: 4 additions & 4 deletions syntax/testdata/errors.star
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#
# TODO(adonovan): lots more tests.

x = 1 +
2 ### "got newline, want primary expression"
x = 1 + ### "got newline, want primary expression"
2

---

Expand Down Expand Up @@ -174,8 +174,8 @@ def f(load): ### `not an identifier`
# A load statement allows a trailing comma.
load("module", "x",)
---
x = 1 +
2 ### "got newline, want primary expression"
x = 1 + ### "got newline, want primary expression"
2
---
def f():
pass
Expand Down

0 comments on commit e6e8e7c

Please sign in to comment.