From e8b6d0c9cd86a44802322d56d13baeeb0e418d15 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 27 Feb 2024 14:04:00 -0800 Subject: [PATCH] go/types, types2: move Checker.langCompat from version.go to expr.go (cleanup) 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley Auto-Submit: Robert Griesemer --- src/cmd/compile/internal/types2/expr.go | 30 ++++++++++++++++++++++ src/cmd/compile/internal/types2/version.go | 30 ---------------------- src/go/types/expr.go | 30 ++++++++++++++++++++++ src/go/types/version.go | 30 ---------------------- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index ca499a17a9..2f9d544a4b 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -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.) diff --git a/src/cmd/compile/internal/types2/version.go b/src/cmd/compile/internal/types2/version.go index 1b6e48e788..bcd47fbb7e 100644 --- a/src/cmd/compile/internal/types2/version.go +++ b/src/cmd/compile/internal/types2/version.go @@ -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, diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 1706184e60..22904cb1b5 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -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.) diff --git a/src/go/types/version.go b/src/go/types/version.go index a11e989b64..565183de04 100644 --- a/src/go/types/version.go +++ b/src/go/types/version.go @@ -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, -- 2.48.1