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/go: incompatible module path check doesn't apply for gopkg.in/yaml.v2 #58721

Open
hyangah opened this issue Feb 24, 2023 · 1 comment
Open
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@hyangah
Copy link
Contributor

hyangah commented Feb 24, 2023

What version of Go are you using (go version)?

$ go version
go version
go version go1.20.1 darwin/amd64

What did you do?

-- go.mod --
module w

go 1.20

require gopkg.in/yaml.v2 v2.4.0

replace gopkg.in/yaml.v2 => gopkg.in/yaml.v3 v3.0.0

-- main.go --
package main

import "gopkg.in/yaml.v2"

func main() {
        var t struct{ A string }
        _, _ = yaml.Marshal(&t)
}

And run go build

Note: the go.mod isn't tidy.

What did you expect to see?

Error related to mismatching module paths. (gopkg.in/yaml.v2 vs gopkg.in/yaml.v3)

What did you see instead?

No error.

go list sees the replacement.

$ go list -f '{{.Module}}' gopkg.in/yaml.v2
gopkg.in/yaml.v2 v2.4.0 => gopkg.in/yaml.v3 v3.0.0

go mod tidy adds gopkg.in/yaml.v3 to indirect require group.
go build was ok as long as go.sum has an entry for v2.

module w

go 1.20

require gopkg.in/yaml.v2 v2.4.0

require gopkg.in/yaml.v3 v3.0.1 // indirect

replace gopkg.in/yaml.v2 => gopkg.in/yaml.v3 v3.0.0

On the other hand,

--- go.mod ---
module e

go 1.20

require (
        github.com/go-logr/logr v1.2.0 // indirect
        k8s.io/klog v1.0.0
)
--- main.go ---
package main

import "k8s.io/klog/v2"

func main() {
        _ = klog.Info
}
--- go.sum ---
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
k8s.io/klog/v2 v2.90.0 h1:VkTxIV/FjRXn1fgNNcKGM8cfmL1Z33ZjXRTVxKCoF5M=
k8s.io/klog/v2 v2.90.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=

go build returns an error (however, not explicitly talks about this path issue)

go build
main.go:3:8: no required module provides package k8s.io/klog/v2; to add it:
        go get k8s.io/klog/v2

go mod tidy update go.mod to the following without error.

module e

go 1.20

require k8s.io/klog/v2 v2.90.0

require github.com/go-logr/logr v1.2.0 // indirect

replace k8s.io/klog => k8s.io/klog/v2 v2.90.0

After that go build succeed. (I don't know why).
But go list -f '{{.Module}}' k8s.io/klog reports an error

$ go list -f '{{.Module}}' k8s.io/klog
module k8s.io/klog provides package k8s.io/klog and is replaced but not required; to add it:
        go get k8s.io/klog
$ go get k8s.io/klog
go: k8s.io/klog/v2@v2.90.0 used for two different module paths (k8s.io/klog and k8s.io/klog/v2)
@thanm thanm added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Feb 27, 2023
@thanm
Copy link
Contributor

thanm commented Feb 27, 2023

@golang/tools-team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants