@@ -878,12 +878,19 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
878
878
// never has to create a types.Package for an indirect dependency,
879
879
// which would then require that such created packages be explicitly
880
880
// inserted back into the Import graph as a final step after export data loading.
881
+ // (Hence this return is after the Types assignment.)
881
882
// The Diamond test exercises this case.
882
883
if ! lpkg .needtypes && ! lpkg .needsrc {
883
884
return
884
885
}
885
886
if ! lpkg .needsrc {
886
- ld .loadFromExportData (lpkg )
887
+ if err := ld .loadFromExportData (lpkg ); err != nil {
888
+ lpkg .Errors = append (lpkg .Errors , Error {
889
+ Pos : "-" ,
890
+ Msg : err .Error (),
891
+ Kind : UnknownError , // e.g. can't find/open/parse export data
892
+ })
893
+ }
887
894
return // not a source package, don't get syntax trees
888
895
}
889
896
@@ -970,7 +977,8 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
970
977
// The config requested loading sources and types, but sources are missing.
971
978
// Add an error to the package and fall back to loading from export data.
972
979
appendError (Error {"-" , fmt .Sprintf ("sources missing for package %s" , lpkg .ID ), ParseError })
973
- ld .loadFromExportData (lpkg )
980
+ _ = ld .loadFromExportData (lpkg ) // ignore any secondary errors
981
+
974
982
return // can't get syntax trees for this package
975
983
}
976
984
@@ -1194,9 +1202,10 @@ func sameFile(x, y string) bool {
1194
1202
return false
1195
1203
}
1196
1204
1197
- // loadFromExportData returns type information for the specified
1205
+ // loadFromExportData ensures that type information is present for the specified
1198
1206
// package, loading it from an export data file on the first request.
1199
- func (ld * loader ) loadFromExportData (lpkg * loaderPackage ) (* types.Package , error ) {
1207
+ // On success it sets lpkg.Types to a new Package.
1208
+ func (ld * loader ) loadFromExportData (lpkg * loaderPackage ) error {
1200
1209
if lpkg .PkgPath == "" {
1201
1210
log .Fatalf ("internal error: Package %s has no PkgPath" , lpkg )
1202
1211
}
@@ -1207,8 +1216,8 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1207
1216
// must be sequential. (Finer-grained locking would require
1208
1217
// changes to the gcexportdata API.)
1209
1218
//
1210
- // The exportMu lock guards the Package.Pkg field and the
1211
- // types.Package it points to, for each Package in the graph.
1219
+ // The exportMu lock guards the lpkg.Types field and the
1220
+ // types.Package it points to, for each loaderPackage in the graph.
1212
1221
//
1213
1222
// Not all accesses to Package.Pkg need to be protected by exportMu:
1214
1223
// graph ordering ensures that direct dependencies of source
@@ -1217,18 +1226,18 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1217
1226
defer ld .exportMu .Unlock ()
1218
1227
1219
1228
if tpkg := lpkg .Types ; tpkg != nil && tpkg .Complete () {
1220
- return tpkg , nil // cache hit
1229
+ return nil // cache hit
1221
1230
}
1222
1231
1223
1232
lpkg .IllTyped = true // fail safe
1224
1233
1225
1234
if lpkg .ExportFile == "" {
1226
1235
// Errors while building export data will have been printed to stderr.
1227
- return nil , fmt .Errorf ("no export data file" )
1236
+ return fmt .Errorf ("no export data file" )
1228
1237
}
1229
1238
f , err := os .Open (lpkg .ExportFile )
1230
1239
if err != nil {
1231
- return nil , err
1240
+ return err
1232
1241
}
1233
1242
defer f .Close ()
1234
1243
@@ -1240,7 +1249,7 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1240
1249
// queries.)
1241
1250
r , err := gcexportdata .NewReader (f )
1242
1251
if err != nil {
1243
- return nil , fmt .Errorf ("reading %s: %v" , lpkg .ExportFile , err )
1252
+ return fmt .Errorf ("reading %s: %v" , lpkg .ExportFile , err )
1244
1253
}
1245
1254
1246
1255
// Build the view.
@@ -1284,7 +1293,7 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1284
1293
// (May modify incomplete packages in view but not create new ones.)
1285
1294
tpkg , err := gcexportdata .Read (r , ld .Fset , view , lpkg .PkgPath )
1286
1295
if err != nil {
1287
- return nil , fmt .Errorf ("reading %s: %v" , lpkg .ExportFile , err )
1296
+ return fmt .Errorf ("reading %s: %v" , lpkg .ExportFile , err )
1288
1297
}
1289
1298
if _ , ok := view ["go.shape" ]; ok {
1290
1299
// Account for the pseudopackage "go.shape" that gets
@@ -1297,8 +1306,7 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1297
1306
1298
1307
lpkg .Types = tpkg
1299
1308
lpkg .IllTyped = false
1300
-
1301
- return tpkg , nil
1309
+ return nil
1302
1310
}
1303
1311
1304
1312
// impliedLoadMode returns loadMode with its dependencies.
0 commit comments