@@ -673,10 +673,15 @@ func goModSummary(m module.Version) (*modFileSummary, error) {
673
673
// ignoring all replacements that may apply to m and excludes that may apply to
674
674
// its dependencies.
675
675
//
676
- // rawGoModSummary cannot be used on the Target module.
676
+ // rawGoModSummary cannot be used on the main module outside of workspace mode .
677
677
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" )
680
685
}
681
686
return rawGoModSummaryCache .Do (m , func () (* modFileSummary , error ) {
682
687
summary := new (modFileSummary )
@@ -724,19 +729,18 @@ var rawGoModSummaryCache par.ErrCache[module.Version, *modFileSummary]
724
729
// rawGoModData returns the content of the go.mod file for module m, ignoring
725
730
// all replacements that may apply to m.
726
731
//
727
- // rawGoModData cannot be used on the Target module.
732
+ // rawGoModData cannot be used on the main module outside of workspace mode .
728
733
//
729
734
// Unlike rawGoModSummary, rawGoModData does not cache its results in memory.
730
735
// Use rawGoModSummary instead unless you specifically need these bytes.
731
736
func rawGoModData (m module.Version ) (name string , data []byte , err error ) {
732
737
if m .Version == "" {
733
- // m is a replacement module with only a file path.
734
-
735
738
dir := m .Path
736
739
if ! filepath .IsAbs (dir ) {
737
740
if inWorkspaceMode () && MainModules .Contains (m .Path ) {
738
741
dir = MainModules .ModRoot (m )
739
742
} else {
743
+ // m is a replacement module with only a file path.
740
744
dir = filepath .Join (replaceRelativeTo (), dir )
741
745
}
742
746
}
0 commit comments