MCPcopy
hub / github.com/golang/tools / typeCheck

Method typeCheck

gopls/internal/cache/analysis.go:723–781  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

721}
722
723func (an *analysisNode) typeCheck(ctx context.Context) (*analysisPackage, error) {
724 ppkg, err := an.batch.getPackage(ctx, an.ph)
725 if err != nil {
726 return nil, err
727 }
728
729 compiles := len(an.ph.mp.Errors) == 0 && len(ppkg.TypeErrors()) == 0
730
731 // The go/analysis framework implicitly promises to deliver
732 // trees with legacy ast.Object resolution. Do that now.
733 files := make([]*ast.File, len(ppkg.CompiledGoFiles()))
734 for i, p := range ppkg.CompiledGoFiles() {
735 p.Resolve()
736 files[i] = p.File
737 if p.ParseErr != nil {
738 compiles = false // parse error
739 }
740 }
741
742 // The fact decoder needs a means to look up a Package by path.
743 pkgLookup := typesLookup(ppkg.Types())
744 factsDecoder := facts.NewDecoderFunc(ppkg.Types(), func(path string) *types.Package {
745 // Note: Decode is called concurrently, and thus so is this function.
746
747 // Does the fact relate to a package reachable through imports?
748 if !an.ph.reachable.MayContain(path) {
749 return nil
750 }
751
752 return pkgLookup(path)
753 })
754
755 var typeErrors []types.Error
756filterErrors:
757 for _, typeError := range ppkg.TypeErrors() {
758 // Suppress type errors in files with parse errors
759 // as parser recovery can be quite lossy (#59888).
760 for _, p := range ppkg.CompiledGoFiles() {
761 if p.ParseErr != nil && astutil.NodeContainsPos(p.File, typeError.Pos) {
762 continue filterErrors
763 }
764 }
765 typeErrors = append(typeErrors, typeError)
766 }
767
768 for _, vdep := range an.succs {
769 if !vdep.compiles {
770 compiles = false // transitive error
771 }
772 }
773
774 return &analysisPackage{
775 pkg: ppkg,
776 files: files,
777 typeErrors: typeErrors,
778 compiles: compiles,
779 factsDecoder: factsDecoder,
780 }, nil

Callers 1

runMethod · 0.95

Calls 10

NewDecoderFuncFunction · 0.92
NodeContainsPosFunction · 0.92
typesLookupFunction · 0.85
appendFunction · 0.85
TypeErrorsMethod · 0.80
CompiledGoFilesMethod · 0.80
TypesMethod · 0.80
MayContainMethod · 0.80
ResolveMethod · 0.65
getPackageMethod · 0.45

Tested by

no test coverage detected