]> Cypherpunks repositories - gostls13.git/commit
go/ast: fix BasicLit.End position for raw strings containing \r
authorAlan Donovan <adonovan@google.com>
Wed, 12 Nov 2025 22:13:40 +0000 (17:13 -0500)
committerAlan Donovan <adonovan@google.com>
Mon, 17 Nov 2025 18:52:48 +0000 (10:52 -0800)
commit8e734ec954ed25e4c41e7d5a6f59ed1c1072ea83
treea137459602a4fc64aa3b88ea42df8374391d57b9
parent592775ec7d8bbc99ee0a1ada56c4490c855f9385
go/ast: fix BasicLit.End position for raw strings containing \r

This CL causes the parser to record in a new field, BasicLit.EndPos,
the actual end position of each literal token, and to use it in
BasicLit.End. Previously, the End was computed heuristically as
Pos + len(Value). This heuristic is incorrect for a multiline
raw string literal on Windows, since the scanner normalizes
\r\n to \n.

Unfortunately the actual end position is not returned by the
Scanner.Scan method, so the scanner and parser conspire
using a global variable in the go/internal/scannerhook
package to communicate.

+ test, api change, relnote

Fixes #76031

Change-Id: I57c18a44e85f7403d470ba23d41dcdcc5a9432c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/720060
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
api/next/76031.txt [new file with mode: 0644]
doc/next/6-stdlib/99-minor/go/ast/76031.md [new file with mode: 0644]
src/go/ast/ast.go
src/go/ast/commentmap_test.go
src/go/ast/example_test.go
src/go/build/deps_test.go
src/go/internal/scannerhooks/hooks.go [new file with mode: 0644]
src/go/parser/parser.go
src/go/parser/parser_test.go
src/go/scanner/scanner.go