Skip to content

Commit 917171f

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
1 parent bc04d4a commit 917171f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cmd/go/internal/modload/modfile.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,15 @@ func goModSummary(m module.Version) (*modFileSummary, error) {
673673
// ignoring all replacements that may apply to m and excludes that may apply to
674674
// its dependencies.
675675
//
676-
// rawGoModSummary cannot be used on the Target module.
676+
// rawGoModSummary cannot be used on the main module outside of workspace mode.
677677
func rawGoModSummary(m module.Version) (*modFileSummary, error) {
678-
if m.Path == "" && MainModules.Contains(m.Path) {
679-
panic("internal error: rawGoModSummary called on the Target module")
678+
if m.Version == "" && !inWorkspaceMode() && MainModules.Contains(m.Path) {
679+
// Calling rawGoModSummary implies that we are treating m as a module whose
680+
// requirements aren't the roots of the module graph and can't be modified.
681+
//
682+
// If we are not in workspace mode, then the requirements of the main module
683+
// are the roots of the module graph and we expect them to be kept consistent.
684+
panic("internal error: rawGoModSummary called on a main module")
680685
}
681686
return rawGoModSummaryCache.Do(m, func() (*modFileSummary, error) {
682687
summary := new(modFileSummary)
@@ -724,19 +729,18 @@ var rawGoModSummaryCache par.ErrCache[module.Version, *modFileSummary]
724729
// rawGoModData returns the content of the go.mod file for module m, ignoring
725730
// all replacements that may apply to m.
726731
//
727-
// rawGoModData cannot be used on the Target module.
732+
// rawGoModData cannot be used on the main module outside of workspace mode.
728733
//
729734
// Unlike rawGoModSummary, rawGoModData does not cache its results in memory.
730735
// Use rawGoModSummary instead unless you specifically need these bytes.
731736
func rawGoModData(m module.Version) (name string, data []byte, err error) {
732737
if m.Version == "" {
733-
// m is a replacement module with only a file path.
734-
735738
dir := m.Path
736739
if !filepath.IsAbs(dir) {
737740
if inWorkspaceMode() && MainModules.Contains(m.Path) {
738741
dir = MainModules.ModRoot(m)
739742
} else {
743+
// m is a replacement module with only a file path.
740744
dir = filepath.Join(replaceRelativeTo(), dir)
741745
}
742746
}

0 commit comments

Comments
 (0)