aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/expr.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2020-12-15 18:38:53 -0500
committerRobert Findley <rfindley@google.com>2020-12-16 17:09:45 +0000
commit09abd23d9efecda2cec40ef6b8ca2cd93e220b40 (patch)
treefaec5cba75660f979cb99cb15dfafd24a8e82a14 /src/go/types/expr.go
parentf38da2cbb66cadebd3b6887c48919269f37ca69d (diff)
downloadgo-09abd23d9efecda2cec40ef6b8ca2cd93e220b40.tar.gz
go-09abd23d9efecda2cec40ef6b8ca2cd93e220b40.zip
[dev.typeparams] go/types: import predicates.go from dev.go2go
Changes from dev.go2go: + Update some isComparable cases to use the seen map. + Tiny updates to comments. Change-Id: Iafd85d60835f17a87f514d9774cae07c183ee6cc Reviewed-on: https://go-review.googlesource.com/c/go/+/278594 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/types/expr.go')
-rw-r--r--src/go/types/expr.go44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index 51714790cb..c57edf8f0d 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -58,11 +58,16 @@ the type (and constant value, if any) is recorded via Info.Types, if present.
type opPredicates map[token.Token]func(Type) bool
-var unaryOpPredicates = opPredicates{
- token.ADD: isNumeric,
- token.SUB: isNumeric,
- token.XOR: isInteger,
- token.NOT: isBoolean,
+var unaryOpPredicates opPredicates
+
+func init() {
+ // Setting unaryOpPredicates in init avoids declaration cycles.
+ unaryOpPredicates = opPredicates{
+ token.ADD: isNumeric,
+ token.SUB: isNumeric,
+ token.XOR: isInteger,
+ token.NOT: isBoolean,
+ }
}
func (check *Checker) op(m opPredicates, x *operand, op token.Token) bool {
@@ -785,20 +790,25 @@ func (check *Checker) shift(x, y *operand, e *ast.BinaryExpr, op token.Token) {
x.mode = value
}
-var binaryOpPredicates = opPredicates{
- token.ADD: func(typ Type) bool { return isNumeric(typ) || isString(typ) },
- token.SUB: isNumeric,
- token.MUL: isNumeric,
- token.QUO: isNumeric,
- token.REM: isInteger,
+var binaryOpPredicates opPredicates
+
+func init() {
+ // Setting binaryOpPredicates in init avoids declaration cycles.
+ binaryOpPredicates = opPredicates{
+ token.ADD: isNumericOrString,
+ token.SUB: isNumeric,
+ token.MUL: isNumeric,
+ token.QUO: isNumeric,
+ token.REM: isInteger,
- token.AND: isInteger,
- token.OR: isInteger,
- token.XOR: isInteger,
- token.AND_NOT: isInteger,
+ token.AND: isInteger,
+ token.OR: isInteger,
+ token.XOR: isInteger,
+ token.AND_NOT: isInteger,
- token.LAND: isBoolean,
- token.LOR: isBoolean,
+ token.LAND: isBoolean,
+ token.LOR: isBoolean,
+ }
}
// The binary expression e may be nil. It's passed in for better error messages only.