aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/check.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-02-03 14:56:13 -0800
committerRobert Griesemer <gri@golang.org>2021-02-04 22:20:33 +0000
commit1ff2fdaaf189e0d7ec73bdbff72558363239f48b (patch)
tree42512eabd1fa092e171cc296c2d1cfad86ec6220 /src/cmd/compile/internal/types2/check.go
parent370e9f58432c51bf3d95308cdc7109e25cc141f6 (diff)
downloadgo-1ff2fdaaf189e0d7ec73bdbff72558363239f48b.tar.gz
go-1ff2fdaaf189e0d7ec73bdbff72558363239f48b.zip
[dev.typeparams] cmd/compile/internal/types2: add support for language version checking
Add the Config.Lang field which may be set to a Go version string, such as "go1.12". This is a string rather than explicit semantic version numbers (such as {1, 12}) for API robustness; a string is more flexible should we need more or different information. Add -lang flag to types2 package for use with (manual) testing when running "go test -run Check$ -lang=... -files=...". While changing flags, look for comma-separated (rather than space- separated) files when providing the -file flag. Check that numeric constant literals, signed shift counts are accepted according to the selected language version. Type alias declarations and overlapping embedded interfaces are not yet checked. Updates #31793. Change-Id: I9ff238ed38a88f377eb2267dc3e8816b89a40635 Reviewed-on: https://go-review.googlesource.com/c/go/+/289509 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/check.go')
-rw-r--r--src/cmd/compile/internal/types2/check.go37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/cmd/compile/internal/types2/check.go b/src/cmd/compile/internal/types2/check.go
index e2c6c4f606..95fb4e1076 100644
--- a/src/cmd/compile/internal/types2/check.go
+++ b/src/cmd/compile/internal/types2/check.go
@@ -88,12 +88,13 @@ type Checker struct {
conf *Config
pkg *Package
*Info
- 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][]syntax.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)
+ 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][]syntax.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
// (initialized by Files, valid only for the duration of check.Files;
@@ -182,16 +183,22 @@ func NewChecker(conf *Config, pkg *Package, info *Info) *Checker {
info = new(Info)
}
+ version, err := parseGoVersion(conf.GoVersion)
+ if err != nil {
+ panic(fmt.Sprintf("invalid Go version %q (%v)", conf.GoVersion, err))
+ }
+
return &Checker{
- conf: conf,
- pkg: pkg,
- Info: info,
- nextId: 1,
- objMap: make(map[Object]*declInfo),
- impMap: make(map[importKey]*Package),
- posMap: make(map[*Interface][]syntax.Pos),
- typMap: make(map[string]*Named),
- pkgCnt: make(map[string]int),
+ conf: conf,
+ pkg: pkg,
+ Info: info,
+ version: version,
+ nextId: 1,
+ objMap: make(map[Object]*declInfo),
+ impMap: make(map[importKey]*Package),
+ posMap: make(map[*Interface][]syntax.Pos),
+ typMap: make(map[string]*Named),
+ pkgCnt: make(map[string]int),
}
}