-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
go/scanner: file's dir lost in go1.11 #26671
Comments
Marking as needs-decision for 1.11, to see if this was indeed an intended change in behavior. |
/cc @mdempsky too. |
It looks like this is not the only issue; also column info is broken by the above commit, see mdempsky/unconvert#30 |
update: the code to prepend the path to file name is not there, commit 546bab8 removes it. The commit message says:
I.e. it was intended behavior (although I don't see traces of discussion about that in #24183, maybe it is elsewhere?). Ergo, packages relying on it now need to do the conversion. |
One thing I still don't understand is why the column info disappears (see mdempsky/unconvert#30). |
Note that " I'm not sure which was meant, but I'd be a bit surprised if changes were required of all the tools out there for 1.11. That sounds like a backwards incompatible change to me. |
Filed #26692 |
unconvert output is broken when using Go 1.11. A quick example: With Go 1.10: > go run unconvert.go github.com/docker/docker/daemon/graphdriver/copy > /home/kir/go/src/github.com/docker/docker/daemon/graphdriver/copy/copy.go:242:28: unnecessary conversion With Go 1.11 beta 2: > go run unconvert.go github.com/docker/docker/daemon/graphdriver/copy > copy.go:242:0: unnecessary conversion Note that there are two issues: - column is 0; - file names have path stripped. The issue with column is filed as golang/go#26692; there is no way to fix it in unconvert. The second issue is currently discussed in golang/go#26671, but it might not be fixed since the new documentation says: > The filenames in line directives now remain untouched by the scanner; > there is no cleanup or conversion of relative into absolute paths > anymore, in sync with what the compiler's scanner/parser are doing. > Any kind of filename transformation has to be done by a client. This > makes the scanner code simpler and also more predictable. So, here's the alternative: if the file name is not absolute, prepend the path as we know it. Signed-off-by: Kir Kolyshkin <[email protected]>
unconvert output is broken when using Go 1.11. A quick example: With Go 1.10: > go run unconvert.go github.com/docker/docker/daemon/graphdriver/copy > /home/kir/go/src/github.com/docker/docker/daemon/graphdriver/copy/copy.go:242:28: unnecessary conversion With Go 1.11 beta 2: > go run unconvert.go github.com/docker/docker/daemon/graphdriver/copy > copy.go:242:0: unnecessary conversion Note that there are two issues: - column is 0; - file names have path stripped. The issue with column is filed as golang/go#26692; there is no way to fix it in unconvert. The second issue is currently discussed in golang/go#26671, but it might not be fixed since the new documentation says: > The filenames in line directives now remain untouched by the scanner; > there is no cleanup or conversion of relative into absolute paths > anymore, in sync with what the compiler's scanner/parser are doing. > Any kind of filename transformation has to be done by a client. This > makes the scanner code simpler and also more predictable. So, here's the alternative: if the file name is not absolute, prepend the path as we know it. Signed-off-by: Kir Kolyshkin <[email protected]>
This was an intentional change that is mentioned in the release notes. |
Mentioning it in the release notes doesn't magically make it exempt from the backwards compatibility promise. It doesn't even qualify as a bug fix, considering the reason given:
Users of |
Yes, it's a backward incompatible change for packages that use go/scanner to read input files with That said, we should certainly be pragmatic about this. What is the real world effect? After all, it only affects files with |
All I know is it broke a few linters (unparam and unconvert mdempsky/unconvert#31), which will certainly break a number of CI workflows once go 1.11 is be out of beta and more people start using it. This is also the reason why there is relative silence about the issue -- most users do not try betas. I have noticed the issue since 1.11beta1 but was aiming for a fix in unconvert, as I failed (or neglected) to track the fix down to golang. |
Edit: Nevermind, it seems to do that already. |
One prominent example of relative line directives in Go code are yacc-based parsers, for example https://github.com/dinedal/textql/tree/master/sqlparser More generally, any transformative offline code generation uses relative line directives, since it wouldn't make sense to check in absolute paths that are specific to someone's development machine. It will affect any 3rd party tool that prints positions in Go code, e.g. all the popular linters. |
@ianlancetaylor it breaks at least 5 popular linters, isn't it enough to not do backward-incompatible change? |
because linters binaries are usually built by go1.10 |
Change https://golang.org/cl/127658 mentions this issue: |
Change https://golang.org/cl/127659 mentions this issue: |
The relevant change was reverted in CL 127658. Updates #26671 Change-Id: I0c555c8e18f4c7e289de56d3ef840d79cf0adac2 Reviewed-on: https://go-review.googlesource.com/127659 Reviewed-by: Brad Fitzpatrick <[email protected]>
What version of Go are you using (
go version
)?go version go1.11beta2 darwin/amd64
Does this issue reproduce with the latest release?
beta
What operating system and processor architecture are you using (
go env
)?Some linters (golangci-lint, unparam, unconvert, unused, megacheck) extract file name from
*ast.File
by callingfset.Position(f.Pos()).Filename
. It was broken in go1.11 by this commit.Demo: https://play.golang.org/p/-r4T4-EtjUu
The bug is that this code block was removed:
and we've lost dir in file's name.
The text was updated successfully, but these errors were encountered: