if s.Name != nil {
s.Name.NamePos = pos[i].Start
}
- s.Path.ValuePos = pos[i].Start
+ updateBasicLitPos(s.Path, pos[i].Start)
s.EndPos = pos[i].End
for _, g := range importComments[s] {
for _, c := range g.cg.List {
return specs
}
+
+// updateBasicLitPos updates lit.Pos,
+// ensuring that lit.End is displaced by the same amount.
+// (See https://go.dev/issue/76395.)
+func updateBasicLitPos(lit *BasicLit, pos token.Pos) {
+ len := lit.End() - lit.Pos()
+ lit.ValuePos = pos
+ if lit.ValueEnd.IsValid() {
+ lit.ValueEnd = pos + len
+ }
+}
spec := *s
path := *s.Path
spec.Path = &path
- spec.Path.ValuePos = groupStart(&spec)
+ updateBasicLitPos(spec.Path, groupStart(&spec))
namedImports = append(namedImports, &spec)
delete(unresolved, n)
}
r, size := utf8.DecodeRuneInString(s)
return size > 0 && unicode.IsLower(r)
}
+
+// updateBasicLitPos updates lit.Pos,
+// ensuring that lit.End is displaced by the same amount.
+// (See https://go.dev/issue/76395.)
+func updateBasicLitPos(lit *ast.BasicLit, pos token.Pos) {
+ len := lit.End() - lit.Pos()
+ lit.ValuePos = pos
+ if lit.ValueEnd.IsValid() {
+ lit.ValueEnd = pos + len
+ }
+}