golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.43k stars 17.59k forks source link

go/ast: (*ast.BasicLit).End() is wrong for raw literals with carriage returns ('\r') #69861

Open mateusz834 opened 3 hours ago

mateusz834 commented 3 hours ago

Same as #41197, but for *ast.BasicLit can happen for raw literal strings.

As per the go spec:

Carriage return characters ('\r') inside raw string literals are discarded from the raw string value.

The End pos is calculated as such:

https://github.com/golang/go/blob/b521ebb55a9b26c8824b219376c7f91f7cda6ec2/src/go/ast/ast.go#L528

We are not storing the end pos in the *ast.BasicLit, so it might be not accurate for raw string literals containing carriage returns.

I think that same as in #41197, we should only document that.

gabyhelp commented 3 hours ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

mateusz834 commented 3 hours ago

CC @griesemer @adonovan

gopherbot commented 3 hours ago

Change https://go.dev/cl/619835 mentions this issue: go/ast: document invalid raw string literal end position containing carriage returns