-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/go: go mod tidy error when importing std package in later go version #40067
Comments
This is mostly working as intended, but the error seems very frustrating.
In this case though, |
By the way, this problem (as expected) also occurs with |
I'm not sure that burying the error would be a good idea: we can't in general tell whether the missing I would be more comfortable with a more narrowly targeted fix. For example, perhaps we should only ignore plausibly-standard-library imports if they occur in files that would normally be excluded by a build constraint. |
|
I'm planning to add a |
Hit this in golang-migrate, which added an
It probably wasn't a big deal when it was only maphash (a bit niche), but this probably is going to become more prevalent given the impact |
I recently hit this issue when I made a shim to support I think the real solution is to decouple the standard library (or as much of it as possible) from the language and tooling releases. This would give the standard library much more flexibility to evolve separately from the language and enable API-breaking v2 changes (probably after generics land). Obviously, this would require a fully thought-out proposal, but the straw man version off the top of my head (ignoring any intricacies of splitting up the stdlib into multiple modules, dealing with their inter-dependencies, and blessed access to runtime internals)... Go 1.x would move to an external stdlib (a snapshot of which would be packaged with the language for self-hosting) and it would implicitly replace usages in pre-Go 1.x modules with their external v1 counterparts (e.g. |
@abursavich, #30241 is a more fleshed-out proposal for standard-library vendoring. Some parts of the standard library (such as The parts of the standard library that are not tightly coupled to the toolchain or runtime could be rewritten as forwarding shims to modules outside the standard library, which could then (under that proposal) be upgraded above — but not downgraded below — the versions required by the standard library. See #30241 for more detail and discussion on that topic. |
I was thinking about this the other day; would it make sense to add a mechanism to ignore these packages' absence during commands that don't know about build tags (e.g., tidy), then once newer versions of Go are released, backport a list of the new packages to the supported releases so that they know that the new packages are "okay"? Given only the previous two releases are supported and the number of new packages added per release are small, I can see this working reasonably well. I recall a few releases ago (1.9 and 1.10?) where some changes were backported to help with the introduction of modules in 1.11, and I find that similar in intention. |
Wouldn't the standard answer be for such replace directives to also be using leading import path segments that don't look like stdlib imports, for exactly this reason? Anyone outside of stdlib using a dotless import path first segment is just asking for trouble, conflicting with future stdlib additions. |
Yes.
Agreed, but plenty of existing Go code (especially closed-source Go code) is written in that style. At this point I do not want to make the migration to modules more difficult or confusing than it already is for those users. |
I've encountered this issue with a somewhat different use case |
@avivataqua, for now you can run (Longer term, I think we should probably change |
This now affects Given: package main
import (
"golang.org/x/tools/godoc/vfs"
)
func main() {
var _ vfs.FileSystem
} And go.mod:
This doesn't affect me personally, but I would sort of expect people to see this in the wild. While this is caused by this issue, I can open a new issue just for cc @rsc (since it was his CL) |
And now
(And I'm still waiting for my distribution to get Go 1.16, which probably won't happen until 1.16.1 to fix some of the ICE/miscompilations |
I did wonder whether the heuristic could be made more specific so that Suppressing errors for missing imports in build-constrained files "feels" too broad. |
The snag here being that Edit: the context for me saying that is the following example:
Works fine with go1.16, but fails with go1.15.8:
|
The approach I suggested in #40067 (comment) would be more targeted to known new packages, though when I suggested this I didn't realize boringcrypto also had its own special packages too (hopefully that's the end of the line). |
Duplicate of #44557. |
Pinned all the hello world chaincode's dependencies to exact versions that are known to have worked in the past for builds. We needed this because the 1.13 go version of the Fabric CLI container could no longer build (tidy+vendor) the dependencies that were built with the newer versions of go such as 1.16 and 1.17. More info about the root cause can be read here: golang/go#40067 By locking the dependencies versions to older ones we we ensured that the older go installation of the Fabric CLI container does not fail. The known-to-be-working dependency versions are coming from packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/fixtures/go/hello-world-contract-fabric-v14/hello-world-contract-go-mod.ts Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Pinned all the hello world chaincode's dependencies to exact versions that are known to have worked in the past for builds. We needed this because the 1.13 go version of the Fabric CLI container could no longer build (tidy+vendor) the dependencies that were built with the newer versions of go such as 1.16 and 1.17. More info about the root cause can be read here: golang/go#40067 By locking the dependencies versions to older ones we we ensured that the older go installation of the Fabric CLI container does not fail. The known-to-be-working dependency versions are coming from packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/fixtures/go/hello-world-contract-fabric-v14/hello-world-contract-go-mod.ts Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
consider a
sample
module with a following filesample.go
:and a
go.mod
:And then in this module, running the following command:
What did you expect to see?
no errors
As
hash/maphash
package is not present ingo1.13
(introduced ingo1.14
), but thesample.go
files should be skipped bygo1.13
thanks to the build tag// +build go1.14
What did you see instead?
I believe that a similar issue occurs in the latest release, maybe with a different error message.
The text was updated successfully, but these errors were encountered: