]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: move Checker.langCompat from version.go to expr.go (cleanup)
authorRobert Griesemer <gri@golang.org>
Tue, 27 Feb 2024 22:04:00 +0000 (14:04 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 28 Feb 2024 02:54:16 +0000 (02:54 +0000)
This makes version.go holding core version checking code only.
No functional changes.

Change-Id: Ia88a48166cad2698765697dd7a8625b56ecc2226
Reviewed-on: https://go-review.googlesource.com/c/go/+/567536
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/version.go
src/go/types/expr.go
src/go/types/version.go

index ca499a17a9f58b783f5cc48b572733e8a95d5b96..2f9d544a4b2fcd8b01862f1a6afc644243506473 100644 (file)
@@ -12,6 +12,7 @@ import (
        "go/constant"
        "go/token"
        . "internal/types/errors"
+       "strings"
 )
 
 /*
@@ -1031,6 +1032,35 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
        }
 }
 
+// langCompat reports an error if the representation of a numeric
+// literal is not compatible with the current language version.
+func (check *Checker) langCompat(lit *syntax.BasicLit) {
+       s := lit.Value
+       if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
+               return
+       }
+       // len(s) > 2
+       if strings.Contains(s, "_") {
+               check.versionErrorf(lit, go1_13, "underscore in numeric literal")
+               return
+       }
+       if s[0] != '0' {
+               return
+       }
+       radix := s[1]
+       if radix == 'b' || radix == 'B' {
+               check.versionErrorf(lit, go1_13, "binary literal")
+               return
+       }
+       if radix == 'o' || radix == 'O' {
+               check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
+               return
+       }
+       if lit.Kind != syntax.IntLit && (radix == 'x' || radix == 'X') {
+               check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
+       }
+}
+
 // exprInternal contains the core of type checking of expressions.
 // Must only be called by rawExpr.
 // (See rawExpr for an explanation of the parameters.)
index 1b6e48e78898a82aa32db918388ad6db04c52a9b..bcd47fbb7e44be63ff04011538675453def5228c 100644 (file)
@@ -9,7 +9,6 @@ import (
        "fmt"
        "go/version"
        "internal/goversion"
-       "strings"
 )
 
 // A goVersion is a Go language version string of the form "go1.%d"
@@ -50,35 +49,6 @@ var (
        go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
 )
 
-// langCompat reports an error if the representation of a numeric
-// literal is not compatible with the current language version.
-func (check *Checker) langCompat(lit *syntax.BasicLit) {
-       s := lit.Value
-       if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
-               return
-       }
-       // len(s) > 2
-       if strings.Contains(s, "_") {
-               check.versionErrorf(lit, go1_13, "underscore in numeric literal")
-               return
-       }
-       if s[0] != '0' {
-               return
-       }
-       radix := s[1]
-       if radix == 'b' || radix == 'B' {
-               check.versionErrorf(lit, go1_13, "binary literal")
-               return
-       }
-       if radix == 'o' || radix == 'O' {
-               check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
-               return
-       }
-       if lit.Kind != syntax.IntLit && (radix == 'x' || radix == 'X') {
-               check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
-       }
-}
-
 // allowVersion reports whether the given package is allowed to use version v.
 func (check *Checker) allowVersion(pkg *Package, at poser, v goVersion) bool {
        // We assume that imported packages have all been checked,
index 1706184e60bd4492b9e5ddd4d841ee63e447d588..22904cb1b520c689bcbc425a10f61c33bbed2fe1 100644 (file)
@@ -13,6 +13,7 @@ import (
        "go/internal/typeparams"
        "go/token"
        . "internal/types/errors"
+       "strings"
 )
 
 /*
@@ -1016,6 +1017,35 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
        }
 }
 
+// langCompat reports an error if the representation of a numeric
+// literal is not compatible with the current language version.
+func (check *Checker) langCompat(lit *ast.BasicLit) {
+       s := lit.Value
+       if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
+               return
+       }
+       // len(s) > 2
+       if strings.Contains(s, "_") {
+               check.versionErrorf(lit, go1_13, "underscore in numeric literal")
+               return
+       }
+       if s[0] != '0' {
+               return
+       }
+       radix := s[1]
+       if radix == 'b' || radix == 'B' {
+               check.versionErrorf(lit, go1_13, "binary literal")
+               return
+       }
+       if radix == 'o' || radix == 'O' {
+               check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
+               return
+       }
+       if lit.Kind != token.INT && (radix == 'x' || radix == 'X') {
+               check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
+       }
+}
+
 // exprInternal contains the core of type checking of expressions.
 // Must only be called by rawExpr.
 // (See rawExpr for an explanation of the parameters.)
index a11e989b6484c1b49fcab666724fe6120e1b3f6a..565183de048886512701e52b975289fb34c5f93e 100644 (file)
@@ -10,7 +10,6 @@ import (
        "go/token"
        "go/version"
        "internal/goversion"
-       "strings"
 )
 
 // A goVersion is a Go language version string of the form "go1.%d"
@@ -51,35 +50,6 @@ var (
        go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
 )
 
-// langCompat reports an error if the representation of a numeric
-// literal is not compatible with the current language version.
-func (check *Checker) langCompat(lit *ast.BasicLit) {
-       s := lit.Value
-       if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
-               return
-       }
-       // len(s) > 2
-       if strings.Contains(s, "_") {
-               check.versionErrorf(lit, go1_13, "underscore in numeric literal")
-               return
-       }
-       if s[0] != '0' {
-               return
-       }
-       radix := s[1]
-       if radix == 'b' || radix == 'B' {
-               check.versionErrorf(lit, go1_13, "binary literal")
-               return
-       }
-       if radix == 'o' || radix == 'O' {
-               check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
-               return
-       }
-       if lit.Kind != token.INT && (radix == 'x' || radix == 'X') {
-               check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
-       }
-}
-
 // allowVersion reports whether the given package is allowed to use version v.
 func (check *Checker) allowVersion(pkg *Package, at positioner, v goVersion) bool {
        // We assume that imported packages have all been checked,