Skip to content

Commit 706c883

Browse files
Reworking typeCheck to check unreachable sources
1 parent 7393cdf commit 706c883

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

compiler/package.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,15 @@ func PrepareAllSources(rootSrcs *sources.Sources, allSources []*sources.Sources,
237237
srcs.Sort()
238238
}
239239

240-
// This will be performed recursively for all dependencies to get the packages for the sources.
241-
if err := rootSrcs.TypeCheck(importer, sizes32, tContext); err != nil {
242-
return err
240+
// This will be performed recursively for all dependencies
241+
// to get the packages for the sources.
242+
// Since some packages might not be recursively reached via the root source,
243+
// e.g. runtime, we need to try to TypeCheck them all here.
244+
// Any package already that has already run TypeCheck will be a no-op.
245+
for _, srcs := range allSources {
246+
if err := srcs.TypeCheck(importer, sizes32, tContext); err != nil {
247+
return err
248+
}
243249
}
244250

245251
// Extract all go:linkname compiler directives from the package source.
@@ -254,6 +260,7 @@ func PrepareAllSources(rootSrcs *sources.Sources, allSources []*sources.Sources,
254260
srcs.Simplify()
255261
}
256262

263+
// Collect all the generic type instances from all the packages.
257264
instances := &typeparams.PackageInstanceSets{}
258265
for _, srcs := range allSources {
259266
srcs.CollectInstances(tContext, instances)

compiler/sources/sources.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ func (s *Sources) Simplify() {
9494
// type information for the supplied AST.
9595
// This will set the Package field on the Sources.
9696
//
97+
// If the Package field is not nil, e.g. this function has already been run,
98+
// this will be a no-op.
99+
//
97100
// This must be called prior to simplify to get the types.Info used by simplify.
98101
func (s *Sources) TypeCheck(importer Importer, sizes types.Sizes, tContext *types.Context) error {
102+
if s.Package != nil {
103+
return nil
104+
}
105+
99106
const errLimit = 10 // Max number of type checking errors to return.
100107

101108
typesInfo := &types.Info{

0 commit comments

Comments
 (0)