Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/internal/src: Pos.String() prints off-by-1 line numbers in presence of line directives #19392

Closed
griesemer opened this issue Mar 4, 2017 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

For the following source:

package p

//line c.go:10
const C = 0      // file line = 4

//line t.go:20
type T int       // file line = 7

//line v.go:30
var V T          // file line = 10

//line f.go:40
func F() {}      // file line = 13

the (line, column) information from the syntax/scanner is mapped to the following src.Pos strings (the last number is the actual line number returned by src.Pos.Line()):

1 0 => x.go:1 1
1 8 => x.go:1 1
4 6 => c.go:10[x.go:3] 4
4 6 => c.go:10[x.go:3] 4
4 8 => c.go:10[x.go:3] 4
4 10 => c.go:10[x.go:3] 4
4 33 => c.go:10[x.go:3] 4
7 5 => t.go:20[x.go:6] 7
7 5 => t.go:20[x.go:6] 7
7 7 => t.go:20[x.go:6] 7
7 7 => t.go:20[x.go:6] 7
10 4 => v.go:30[x.go:9] 10
10 4 => v.go:30[x.go:9] 10
10 6 => v.go:30[x.go:9] 10
10 6 => v.go:30[x.go:9] 10
13 5 => f.go:40[x.go:12] 13
13 5 => f.go:40[x.go:12] 13
13 6 => f.go:40[x.go:12] 13
13 9 => f.go:40[x.go:12] 13
13 9 => f.go:40[x.go:12] 13

The line numbers reported in [] brackets are the line numbers of the line directive (+ delta). They are off-by-1 for the purpose of the Pos.String(). The fix is trivial but must be made at the right place.

@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 4, 2017
@griesemer griesemer added this to the Go1.9Early milestone Mar 4, 2017
@griesemer griesemer self-assigned this Mar 4, 2017
@griesemer
Copy link
Contributor Author

This will address a comment in #19391.

@gopherbot
Copy link

CL https://golang.org/cl/37932 mentions this issue.

@golang golang locked and limited conversation to collaborators Mar 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants