Skip to content

cmd/go: 'go list -mod=readonly' erroneously resolves imports from replaced modules #41577

Closed
@bcmills

Description

@bcmills

When -mod=readonly is set, go list should refuse to resolve missing dependencies, and normally does.

However, if the dependency can be satisfied by adding a requirement on a module mentioned in a replace directive, the usual lookup disabled error message is suppressed, and go list instead fails with updates to go.mod needed:

example.com$ go version
go version devel +150bd4ff Wed Sep 23 07:51:17 2020 +0000 linux/amd64

example.com$ go list -mod=readonly example.com/x
cannot find module providing package example.com/x: import lookup disabled by -mod=readonly

example.com$ go mod edit -replace=example.com/x@v0.1.0=./x

example.com$ go list -mod=readonly example.com/x
go: found example.com/x in example.com/x v0.1.0
go: updates to go.mod needed, disabled by -mod=readonly

-- go.mod --
module example.com

go 1.16
-- x/go.mod --
module example.com/x

go 1.16
-- x/x.go --
package x

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Sep 23, 2020
added this to the Go1.16 milestone on Sep 23, 2020
self-assigned this
on Sep 23, 2020
gopherbot

gopherbot commented on Sep 29, 2020

@gopherbot
Contributor

Change https://golang.org/cl/258220 mentions this issue: cmd/go/internal/modload: rework replacements in the Query functions

gopherbot

gopherbot commented on Oct 17, 2020

@gopherbot
Contributor

Change https://golang.org/cl/263266 mentions this issue: cmd/go/internal/modload: fix sort condition in (*replacementRepo).Versions

bcmills

bcmills commented on Oct 28, 2020

@bcmills
ContributorAuthor

Fixed by CL 258220.

locked and limited conversation to collaborators on Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bcmills@gopherbot

        Issue actions

          cmd/go: 'go list -mod=readonly' erroneously resolves imports from replaced modules · Issue #41577 · golang/go