From: Bryan C. Mills Date: Wed, 26 Apr 2023 06:43:06 +0000 (-0400) Subject: cmd/go/internal/modload: fix sanity check in rawGoModSummary X-Git-Tag: go1.21rc1~452 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=917171f5645a70a65cab8cc5f901a905ef6df601;p=gostls13.git cmd/go/internal/modload: fix sanity check in rawGoModSummary m.Path is never empty for a module in the build list; this fixes a typo from CL 334932. Change-Id: I5328081ba3bcf5eeac9a1b21a03969ba82ab20ab Reviewed-on: https://go-review.googlesource.com/c/go/+/489076 Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Michael Matloob Run-TryBot: Bryan Mills --- diff --git a/src/cmd/go/internal/modload/modfile.go b/src/cmd/go/internal/modload/modfile.go index 59915792ad..61dcabafb7 100644 --- a/src/cmd/go/internal/modload/modfile.go +++ b/src/cmd/go/internal/modload/modfile.go @@ -673,10 +673,15 @@ func goModSummary(m module.Version) (*modFileSummary, error) { // ignoring all replacements that may apply to m and excludes that may apply to // its dependencies. // -// rawGoModSummary cannot be used on the Target module. +// rawGoModSummary cannot be used on the main module outside of workspace mode. func rawGoModSummary(m module.Version) (*modFileSummary, error) { - if m.Path == "" && MainModules.Contains(m.Path) { - panic("internal error: rawGoModSummary called on the Target module") + if m.Version == "" && !inWorkspaceMode() && MainModules.Contains(m.Path) { + // Calling rawGoModSummary implies that we are treating m as a module whose + // requirements aren't the roots of the module graph and can't be modified. + // + // If we are not in workspace mode, then the requirements of the main module + // are the roots of the module graph and we expect them to be kept consistent. + panic("internal error: rawGoModSummary called on a main module") } return rawGoModSummaryCache.Do(m, func() (*modFileSummary, error) { summary := new(modFileSummary) @@ -724,19 +729,18 @@ var rawGoModSummaryCache par.ErrCache[module.Version, *modFileSummary] // rawGoModData returns the content of the go.mod file for module m, ignoring // all replacements that may apply to m. // -// rawGoModData cannot be used on the Target module. +// rawGoModData cannot be used on the main module outside of workspace mode. // // Unlike rawGoModSummary, rawGoModData does not cache its results in memory. // Use rawGoModSummary instead unless you specifically need these bytes. func rawGoModData(m module.Version) (name string, data []byte, err error) { if m.Version == "" { - // m is a replacement module with only a file path. - dir := m.Path if !filepath.IsAbs(dir) { if inWorkspaceMode() && MainModules.Contains(m.Path) { dir = MainModules.ModRoot(m) } else { + // m is a replacement module with only a file path. dir = filepath.Join(replaceRelativeTo(), dir) } }