1
0
mirror of https://github.com/golang/go synced 2024-11-16 22:04:50 -07:00

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 <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>
This commit is contained in:
Robert Griesemer 2024-02-27 14:04:00 -08:00 committed by Gopher Robot
parent 5e00352b9b
commit e8b6d0c9cd
4 changed files with 60 additions and 60 deletions

View 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.)

View 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,

View 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.)

View 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,