golang / go

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

x/tools/gopls: investigate if 'fixed' syntax needs more accurate positions #64335

Open findleyr opened 9 months ago

findleyr commented 9 months ago

The implementation of file-based versions (https://go.dev/issue/62605) uses positions to associate syntax with a per-file go version.

gopls has logic to fix syntax before type checking which likely invalidates some positions. For example, I think this manifests as https://github.com/golang/go/issues/64320#issue-2004980112, where we can't position a type checker error.

This is a reminder issue that this logic may need to be more careful about preserving valid positions, such as by setting the position of synthetic syntax to the file base. Otherwise, we may produce inaccurate type checking results in the future.

Not super urgent, because at the moment there is no file version that can affect type checker rules. You can't downgrade a file to before 1.21, when the semantics of file versions changed.

Putting this in gopls@v0.16, though if this slips to v0.17 that's OK.

CC @adonovan @griesemer for awareness of this type of subtlety.

gopherbot commented 9 months ago

Change https://go.dev/cl/546655 mentions this issue: gopls/internal/lsp/cache/parsego: clamp positions when fixing statements