[tools] internal/astutil: fix \r bug in PosInStringLiteral

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Feb 24, 2026, 2:32:07 PM (14 hours ago) Feb 24
to Alan Donovan, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Hongxiang Jiang, Go LUCI, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
internal/astutil: fix \r bug in PosInStringLiteral

While investigating golang/go#77675 I realized that there
would be a similar problem in PosInStringLiteral:

BasicLit.Value does not record \r carriage returns,
so we need to account for them by pretending we saw
one before each \n iff the literal contained any
carriage returns, which we can infer from a discrepancy
between its Pos-End range and the length of Value.

This change fixes that bug and adds the missing test.

(Ideally the logic in Hover--see CL 748322--would be moved to a
function in this package that is dual to PosInStringLiteral and
also has a test.)

Updates golang/go#77675
Change-Id: I1be3cbe2dddd72d936f399f177fe138541dde240
Auto-Submit: Alan Donovan <adon...@google.com>
Reviewed-by: Hongxiang Jiang <hxj...@golang.org>
Files:
  • M internal/astutil/stringlit.go
Change size: S
Delta: 1 file changed, 10 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Hongxiang Jiang
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I1be3cbe2dddd72d936f399f177fe138541dde240
Gerrit-Change-Number: 748480
Gerrit-PatchSet: 2
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages