Description
As we work on making gopls incremental in #57987, we rely heavily on being able to export and then re-import both valid and invalid types.Packages.
I have just encountered the first instance where this fails, but only with Go 1.17:
The following code is invalid at 1.17, but valid at 1.18:
type A struct {
X int
}
type B interface {
A
}
(on 1.18, B is a valid constraint interface).
Go 1.17 contained much code supporting generics behind the scenes in go/types, and so reports an error at the embedding of A, but does not record the embedded type as Typ[Invalid]. Then importing fails here:
https://cs.opensource.google/go/go/+/refs/tags/go1.17.9:src/go/types/type.go;l=574;drc=66007e5cfc9e151485791d440b7e67d44af1b29f
This is an unfortunate instance where Go 1.17 is long since not supported by the Go project, but still supported by gopls until at least Go 1.21 comes out. I think it suffices for us to let the import fail, but we need to make sure we produce accurate diagnostics for this code at Go 1.17, and get reasonable behavior in importing packages.
CC @adonovan
Activity
adonovan commentedon May 11, 2023
Fortunately this bug will soon be firmly in the past, but in general I don't know what we can really do fix future occurrences of similar problems. We could backport a fix to the go1.X branch, cut a point release, and suggest that affected users upgrade to it. That might be worthwhile for the most recent value of X.
In this case, I get a diagnostic on the import of the form
cannot import %q (%v), possibly version skew - reinstall package
, indicating that there was a recovered panic. The "version skew" is wrong and it's not clear what "reinstall package" means. If the user misinterprets this as a suggestion to install the Debian or Homebrew package for a newer version of Go, then by mere good fortune this should actual help.Perhaps we should clarify the warning message for recovered panics going forward. I'm not sure what else there is to do here.
findleyr commentedon May 12, 2023
As discussed, let's just improve this error message to not be misleading. We should not hint at "version skew" as it's not possible for gopls, and it potentially very confusing to our users.
Reassigning to @adonovan for a suitable wording :)
gopherbot commentedon May 12, 2023
Change https://go.dev/cl/494676 mentions this issue:
internal/gcimporter: improve error handling
internal/gcimporter: improve error handling