@@ -415,7 +415,7 @@ type loader struct {
415
415
parseCacheMu sync.Mutex
416
416
exportMu sync.Mutex // enforces mutual exclusion of exportdata operations
417
417
418
- // Config.Mode contains the implied mode (see implyLoadMode ).
418
+ // Config.Mode contains the implied mode (see impliedLoadMode ).
419
419
// Implied mode contains all the fields we need the data for.
420
420
// In requestedMode there are the actually requested fields.
421
421
// We'll zero them out before returning packages to the user.
@@ -463,6 +463,10 @@ func newLoader(cfg *Config) *loader {
463
463
}
464
464
}
465
465
466
+ // Save the actually requested fields. We'll zero them out before returning packages to the user.
467
+ ld .requestedMode = ld .Mode
468
+ ld .Mode = impliedLoadMode (ld .Mode )
469
+
466
470
if ld .Mode & NeedTypes != 0 {
467
471
if ld .Fset == nil {
468
472
ld .Fset = token .NewFileSet ()
@@ -478,9 +482,6 @@ func newLoader(cfg *Config) *loader {
478
482
}
479
483
}
480
484
481
- // Save the actually requested fields. We'll zero them out before returning packages to the user.
482
- ld .requestedMode = ld .Mode
483
- ld .implyLoadMode ()
484
485
return ld
485
486
}
486
487
@@ -1080,23 +1081,23 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1080
1081
return tpkg , nil
1081
1082
}
1082
1083
1083
- // implyLoadMode adds dependencies for choosed LoadMode in ld.Mode
1084
- func ( ld * loader ) implyLoadMode () {
1085
- if ld . Mode & NeedTypesInfo != 0 && ld . Mode & NeedImports == 0 {
1084
+ // impliedLoadMode returns loadMode with it's dependencies
1085
+ func impliedLoadMode ( loadMode LoadMode ) LoadMode {
1086
+ if loadMode & NeedTypesInfo != 0 && loadMode & NeedImports == 0 {
1086
1087
// If NeedTypesInfo, go/packages needs to do typechecking itself so it can
1087
1088
// associate type info with the AST. To do so, we need the export data
1088
1089
// for dependencies, which means we need to ask for the direct dependencies.
1089
1090
// NeedImports is used to ask for the direct dependencies.
1090
- ld .Mode |= NeedImports
1091
- ld .Logf ("Added load mode dependency of NeedTypesInfo: NeedImports" )
1091
+ loadMode |= NeedImports
1092
1092
}
1093
1093
1094
- if ld . Mode & NeedDeps != 0 && ld . Mode & NeedImports == 0 {
1094
+ if loadMode & NeedDeps != 0 && loadMode & NeedImports == 0 {
1095
1095
// With NeedDeps we need to load at least direct dependencies.
1096
1096
// NeedImports is used to ask for the direct dependencies.
1097
- ld .Mode |= NeedImports
1098
- ld .Logf ("Added load mode dependency of NeedDeps: NeedImports" )
1097
+ loadMode |= NeedImports
1099
1098
}
1099
+
1100
+ return loadMode
1100
1101
}
1101
1102
1102
1103
func usesExportData (cfg * Config ) bool {
0 commit comments