]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/check.go
[dev.typeparams] merge master (2f0da6d) into dev.typeparams
[gostls13.git] / src / go / types / check.go
index 3bc8ee067c2b1b516e98bbcfbc447b91c712fc9c..57c6a2e7b89ff059a31acccf2fc64dee5540ec6c 100644 (file)
@@ -20,18 +20,18 @@ const (
        trace = false // turn on for detailed type resolution traces
 )
 
-// If Strict is set, the type-checker enforces additional
+// If forceStrict is set, the type-checker enforces additional
 // rules not specified by the Go 1 spec, but which will
 // catch guaranteed run-time errors if the respective
 // code is executed. In other words, programs passing in
-// Strict mode are Go 1 compliant, but not all Go 1 programs
-// will pass in Strict mode. The additional rules are:
+// strict mode are Go 1 compliant, but not all Go 1 programs
+// will pass in strict mode. The additional rules are:
 //
 // - A type assertion x.(T) where T is an interface type
 //   is invalid if any (statically known) method that exists
 //   for both x and T have different signatures.
 //
-const strict = false
+const forceStrict = false
 
 // exprInfo stores information about an untyped expression.
 type exprInfo struct {
@@ -86,9 +86,11 @@ type Checker struct {
        pkg  *Package
        *Info
        version version                    // accepted language version
+       nextId  uint64                     // unique Id for type parameters (first valid Id is 1)
        objMap  map[Object]*declInfo       // maps package-level objects and (non-interface) methods to declaration info
        impMap  map[importKey]*Package     // maps (import path, source directory) to (complete or fake) package
        posMap  map[*Interface][]token.Pos // maps interface types to lists of embedded interface positions
+       typMap  map[string]*Named          // maps an instantiated named type hash to a *Named type
        pkgCnt  map[string]int             // counts number of imported packages with a given name (for better error messages)
 
        // information collected during type-checking of a set of package files
@@ -189,9 +191,11 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Ch
                pkg:     pkg,
                Info:    info,
                version: version,
+               nextId:  1,
                objMap:  make(map[Object]*declInfo),
                impMap:  make(map[importKey]*Package),
                posMap:  make(map[*Interface][]token.Pos),
+               typMap:  make(map[string]*Named),
                pkgCnt:  make(map[string]int),
        }
 }
@@ -278,6 +282,10 @@ func (check *Checker) checkFiles(files []*ast.File) (err error) {
 
        check.recordUntyped()
 
+       if check.Info != nil {
+               sanitizeInfo(check.Info)
+       }
+
        check.pkg.complete = true
 
        // TODO(rFindley) There's more memory we should release at this point.
@@ -383,6 +391,14 @@ func (check *Checker) recordCommaOkTypes(x ast.Expr, a [2]Type) {
        }
 }
 
+func (check *Checker) recordInferred(call ast.Expr, targs []Type, sig *Signature) {
+       assert(call != nil)
+       assert(sig != nil)
+       if m := check.Inferred; m != nil {
+               m[call] = Inferred{targs, sig}
+       }
+}
+
 func (check *Checker) recordDef(id *ast.Ident, obj Object) {
        assert(id != nil)
        if m := check.Defs; m != nil {