Skip to content

Commit

Permalink
syntax: report start-of-token pos for parsePrimary errors
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 28, 2024
1 parent 981680b commit 76f96b5
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 76f96b5

Please sign in to comment.