Skip to content

Commit e8b6d0c

Browse files
griesemergopherbot
authored andcommitted
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>
1 parent 5e00352 commit e8b6d0c

File tree

4 files changed

+60
-60
lines changed

4 files changed

+60
-60
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go/constant"
1313
"go/token"
1414
. "internal/types/errors"
15+
"strings"
1516
)
1617

1718
/*
@@ -1031,6 +1032,35 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
10311032
}
10321033
}
10331034

1035+
// langCompat reports an error if the representation of a numeric
1036+
// literal is not compatible with the current language version.
1037+
func (check *Checker) langCompat(lit *syntax.BasicLit) {
1038+
s := lit.Value
1039+
if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
1040+
return
1041+
}
1042+
// len(s) > 2
1043+
if strings.Contains(s, "_") {
1044+
check.versionErrorf(lit, go1_13, "underscore in numeric literal")
1045+
return
1046+
}
1047+
if s[0] != '0' {
1048+
return
1049+
}
1050+
radix := s[1]
1051+
if radix == 'b' || radix == 'B' {
1052+
check.versionErrorf(lit, go1_13, "binary literal")
1053+
return
1054+
}
1055+
if radix == 'o' || radix == 'O' {
1056+
check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
1057+
return
1058+
}
1059+
if lit.Kind != syntax.IntLit && (radix == 'x' || radix == 'X') {
1060+
check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
1061+
}
1062+
}
1063+
10341064
// exprInternal contains the core of type checking of expressions.
10351065
// Must only be called by rawExpr.
10361066
// (See rawExpr for an explanation of the parameters.)

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"go/version"
1111
"internal/goversion"
12-
"strings"
1312
)
1413

1514
// A goVersion is a Go language version string of the form "go1.%d"
@@ -50,35 +49,6 @@ var (
5049
go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
5150
)
5251

53-
// langCompat reports an error if the representation of a numeric
54-
// literal is not compatible with the current language version.
55-
func (check *Checker) langCompat(lit *syntax.BasicLit) {
56-
s := lit.Value
57-
if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
58-
return
59-
}
60-
// len(s) > 2
61-
if strings.Contains(s, "_") {
62-
check.versionErrorf(lit, go1_13, "underscore in numeric literal")
63-
return
64-
}
65-
if s[0] != '0' {
66-
return
67-
}
68-
radix := s[1]
69-
if radix == 'b' || radix == 'B' {
70-
check.versionErrorf(lit, go1_13, "binary literal")
71-
return
72-
}
73-
if radix == 'o' || radix == 'O' {
74-
check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
75-
return
76-
}
77-
if lit.Kind != syntax.IntLit && (radix == 'x' || radix == 'X') {
78-
check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
79-
}
80-
}
81-
8252
// allowVersion reports whether the given package is allowed to use version v.
8353
func (check *Checker) allowVersion(pkg *Package, at poser, v goVersion) bool {
8454
// We assume that imported packages have all been checked,

src/go/types/expr.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"go/internal/typeparams"
1414
"go/token"
1515
. "internal/types/errors"
16+
"strings"
1617
)
1718

1819
/*
@@ -1016,6 +1017,35 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
10161017
}
10171018
}
10181019

1020+
// langCompat reports an error if the representation of a numeric
1021+
// literal is not compatible with the current language version.
1022+
func (check *Checker) langCompat(lit *ast.BasicLit) {
1023+
s := lit.Value
1024+
if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
1025+
return
1026+
}
1027+
// len(s) > 2
1028+
if strings.Contains(s, "_") {
1029+
check.versionErrorf(lit, go1_13, "underscore in numeric literal")
1030+
return
1031+
}
1032+
if s[0] != '0' {
1033+
return
1034+
}
1035+
radix := s[1]
1036+
if radix == 'b' || radix == 'B' {
1037+
check.versionErrorf(lit, go1_13, "binary literal")
1038+
return
1039+
}
1040+
if radix == 'o' || radix == 'O' {
1041+
check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
1042+
return
1043+
}
1044+
if lit.Kind != token.INT && (radix == 'x' || radix == 'X') {
1045+
check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
1046+
}
1047+
}
1048+
10191049
// exprInternal contains the core of type checking of expressions.
10201050
// Must only be called by rawExpr.
10211051
// (See rawExpr for an explanation of the parameters.)

src/go/types/version.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"go/token"
1111
"go/version"
1212
"internal/goversion"
13-
"strings"
1413
)
1514

1615
// A goVersion is a Go language version string of the form "go1.%d"
@@ -51,35 +50,6 @@ var (
5150
go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
5251
)
5352

54-
// langCompat reports an error if the representation of a numeric
55-
// literal is not compatible with the current language version.
56-
func (check *Checker) langCompat(lit *ast.BasicLit) {
57-
s := lit.Value
58-
if len(s) <= 2 || check.allowVersion(check.pkg, lit, go1_13) {
59-
return
60-
}
61-
// len(s) > 2
62-
if strings.Contains(s, "_") {
63-
check.versionErrorf(lit, go1_13, "underscore in numeric literal")
64-
return
65-
}
66-
if s[0] != '0' {
67-
return
68-
}
69-
radix := s[1]
70-
if radix == 'b' || radix == 'B' {
71-
check.versionErrorf(lit, go1_13, "binary literal")
72-
return
73-
}
74-
if radix == 'o' || radix == 'O' {
75-
check.versionErrorf(lit, go1_13, "0o/0O-style octal literal")
76-
return
77-
}
78-
if lit.Kind != token.INT && (radix == 'x' || radix == 'X') {
79-
check.versionErrorf(lit, go1_13, "hexadecimal floating-point literal")
80-
}
81-
}
82-
8353
// allowVersion reports whether the given package is allowed to use version v.
8454
func (check *Checker) allowVersion(pkg *Package, at positioner, v goVersion) bool {
8555
// We assume that imported packages have all been checked,

0 commit comments

Comments
 (0)