@@ -763,6 +763,7 @@ func QueryPattern(loaderstate *State, ctx context.Context, pattern, query string
763763 return nil , modOnly , nil
764764 } else if len (mainModuleMatches ) != 0 {
765765 return nil , nil , & QueryMatchesMainModulesError {
766+ LoaderState : loaderstate ,
766767 MainModules : mainModuleMatches ,
767768 Pattern : pattern ,
768769 Query : query ,
@@ -826,8 +827,9 @@ func QueryPattern(loaderstate *State, ctx context.Context, pattern, query string
826827
827828 if len (mainModuleMatches ) > 0 && len (results ) == 0 && modOnly == nil && errors .Is (err , fs .ErrNotExist ) {
828829 return nil , nil , & QueryMatchesMainModulesError {
829- Pattern : pattern ,
830- Query : query ,
830+ LoaderState : loaderstate ,
831+ Pattern : pattern ,
832+ Query : query ,
831833 }
832834 }
833835 return slices .Clip (results ), modOnly , err
@@ -1112,7 +1114,7 @@ type versionRepo interface {
11121114 CheckReuse (context.Context , * codehost.Origin ) error
11131115 Versions (ctx context.Context , prefix string ) (* modfetch.Versions , error )
11141116 Stat (ctx context.Context , rev string ) (* modfetch.RevInfo , error )
1115- Latest (context.Context ) (* modfetch.RevInfo , error )
1117+ Latest (ctx context.Context ) (* modfetch.RevInfo , error )
11161118}
11171119
11181120var _ versionRepo = modfetch .Repo (nil )
@@ -1130,7 +1132,7 @@ func lookupRepo(loaderstate *State, ctx context.Context, proxy, path string) (re
11301132 if loaderstate .MainModules == nil {
11311133 return repo , err
11321134 } else if _ , ok := loaderstate .MainModules .HighestReplaced ()[path ]; ok {
1133- return & replacementRepo {repo : repo }, nil
1135+ return & replacementRepo {repo : repo , loaderstate : loaderstate }, nil
11341136 }
11351137
11361138 return repo , err
@@ -1163,7 +1165,8 @@ func (er emptyRepo) Latest(ctx context.Context) (*modfetch.RevInfo, error) { ret
11631165// modules, so a replacementRepo should only be constructed for a module that
11641166// actually has one or more valid replacements.
11651167type replacementRepo struct {
1166- repo versionRepo
1168+ repo versionRepo
1169+ loaderstate * State
11671170}
11681171
11691172var _ versionRepo = (* replacementRepo )(nil )
@@ -1186,8 +1189,8 @@ func (rr *replacementRepo) Versions(ctx context.Context, prefix string) (*modfet
11861189 }
11871190
11881191 versions := repoVersions .List
1189- for _ , mm := range LoaderState .MainModules .Versions () {
1190- if index := LoaderState .MainModules .Index (mm ); index != nil && len (index .replace ) > 0 {
1192+ for _ , mm := range rr . loaderstate .MainModules .Versions () {
1193+ if index := rr . loaderstate .MainModules .Index (mm ); index != nil && len (index .replace ) > 0 {
11911194 path := rr .ModulePath ()
11921195 for m := range index .replace {
11931196 if m .Path == path && strings .HasPrefix (m .Version , prefix ) && m .Version != "" && ! module .IsPseudoVersion (m .Version ) {
@@ -1215,8 +1218,8 @@ func (rr *replacementRepo) Stat(ctx context.Context, rev string) (*modfetch.RevI
12151218 return info , err
12161219 }
12171220 var hasReplacements bool
1218- for _ , v := range LoaderState .MainModules .Versions () {
1219- if index := LoaderState .MainModules .Index (v ); index != nil && len (index .replace ) > 0 {
1221+ for _ , v := range rr . loaderstate .MainModules .Versions () {
1222+ if index := rr . loaderstate .MainModules .Index (v ); index != nil && len (index .replace ) > 0 {
12201223 hasReplacements = true
12211224 }
12221225 }
@@ -1239,7 +1242,7 @@ func (rr *replacementRepo) Stat(ctx context.Context, rev string) (*modfetch.RevI
12391242 }
12401243 }
12411244
1242- if r := Replacement (LoaderState , module.Version {Path : path , Version : v }); r .Path == "" {
1245+ if r := Replacement (rr . loaderstate , module.Version {Path : path , Version : v }); r .Path == "" {
12431246 return info , err
12441247 }
12451248 return rr .replacementStat (v )
@@ -1249,7 +1252,7 @@ func (rr *replacementRepo) Latest(ctx context.Context) (*modfetch.RevInfo, error
12491252 info , err := rr .repo .Latest (ctx )
12501253 path := rr .ModulePath ()
12511254
1252- if v , ok := LoaderState .MainModules .HighestReplaced ()[path ]; ok {
1255+ if v , ok := rr . loaderstate .MainModules .HighestReplaced ()[path ]; ok {
12531256 if v == "" {
12541257 // The only replacement is a wildcard that doesn't specify a version, so
12551258 // synthesize a pseudo-version with an appropriate major version and a
@@ -1284,13 +1287,15 @@ func (rr *replacementRepo) replacementStat(v string) (*modfetch.RevInfo, error)
12841287// a version of the main module that cannot be satisfied.
12851288// (The main module's version cannot be changed.)
12861289type QueryMatchesMainModulesError struct {
1290+ LoaderState * State
12871291 MainModules []module.Version
12881292 Pattern string
12891293 Query string
12901294}
12911295
12921296func (e * QueryMatchesMainModulesError ) Error () string {
1293- if LoaderState .MainModules .Contains (e .Pattern ) {
1297+ // TODO(jitsu): break dependency on loaderstate
1298+ if e .LoaderState .MainModules .Contains (e .Pattern ) {
12941299 return fmt .Sprintf ("can't request version %q of the main module (%s)" , e .Query , e .Pattern )
12951300 }
12961301
0 commit comments