github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/check.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file implements the Check function, which drives type-checking. 6 7 package types2 8 9 import ( 10 "github.com/shogo82148/std/cmd/compile/internal/syntax" 11 ) 12 13 // A Checker maintains the state of the type checker. 14 // It must be created with NewChecker. 15 type Checker struct { 16 17 // If enableAlias is set, alias declarations produce an Alias type. 18 // Otherwise the alias information is only in the type name, which 19 // points directly to the actual (aliased) type. 20 enableAlias bool 21 22 conf *Config 23 ctxt *Context 24 pkg *Package 25 *Info 26 version goVersion 27 nextID uint64 28 objMap map[Object]*declInfo 29 impMap map[importKey]*Package 30 31 // pkgPathMap maps package names to the set of distinct import paths we've 32 // seen for that name, anywhere in the import graph. It is used for 33 // disambiguating package names in error messages. 34 // 35 // pkgPathMap is allocated lazily, so that we don't pay the price of building 36 // it on the happy path. seenPkgMap tracks the packages that we've already 37 // walked. 38 pkgPathMap map[string]map[string]bool 39 seenPkgMap map[*Package]bool 40 41 // information collected during type-checking of a set of package files 42 // (initialized by Files, valid only for the duration of check.Files; 43 // maps and lists are allocated on demand) 44 files []*syntax.File 45 versions map[*syntax.PosBase]string 46 imports []*PkgName 47 dotImportMap map[dotImportKey]*PkgName 48 recvTParamMap map[*syntax.Name]*TypeParam 49 brokenAliases map[*TypeName]bool 50 unionTypeSets map[*Union]*_TypeSet 51 mono monoGraph 52 53 firstErr error 54 methods map[*TypeName][]*Func 55 untyped map[syntax.Expr]exprInfo 56 delayed []action 57 objPath []Object 58 cleaners []cleaner 59 60 // environment within which the current object is type-checked (valid only 61 // for the duration of type-checking a specific object) 62 environment 63 64 // debugging 65 indent int 66 } 67 68 // NewChecker returns a new Checker instance for a given package. 69 // Package files may be added incrementally via checker.Files. 70 func NewChecker(conf *Config, pkg *Package, info *Info) *Checker 71 72 // Files checks the provided files as part of the checker's package. 73 func (check *Checker) Files(files []*syntax.File) error