]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: resolve decl cycle the same way as...
authorRobert Griesemer <gri@golang.org>
Fri, 19 Feb 2021 17:39:01 +0000 (09:39 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 19 Feb 2021 19:39:03 +0000 (19:39 +0000)
Minor adjustment to match go/types more closely.

Change-Id: Id79c51f0ecd8cda0f5b68f6e961500f7f22f7115
Reviewed-on: https://go-review.googlesource.com/c/go/+/294270
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>

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

index a284c8c8b6f2071f54cb29a463be46fbbd9d87dd..584b8ee6a01b665f1d583935e32f4300ff91430f 100644 (file)
@@ -59,11 +59,16 @@ the type (and constant value, if any) is recorded via Info.Types, if present.
 
 type opPredicates map[syntax.Operator]func(Type) bool
 
-var unaryOpPredicates = opPredicates{
-       syntax.Add: isNumeric,
-       syntax.Sub: isNumeric,
-       syntax.Xor: isInteger,
-       syntax.Not: isBoolean,
+var unaryOpPredicates opPredicates
+
+func init() {
+       // Setting unaryOpPredicates in init avoids declaration cycles.
+       unaryOpPredicates = opPredicates{
+               syntax.Add: isNumeric,
+               syntax.Sub: isNumeric,
+               syntax.Xor: isInteger,
+               syntax.Not: isBoolean,
+       }
 }
 
 func (check *Checker) op(m opPredicates, x *operand, op syntax.Operator) bool {
@@ -896,20 +901,25 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
        x.mode = value
 }
 
-var binaryOpPredicates = opPredicates{
-       syntax.Add: isNumericOrString,
-       syntax.Sub: isNumeric,
-       syntax.Mul: isNumeric,
-       syntax.Div: isNumeric,
-       syntax.Rem: isInteger,
+var binaryOpPredicates opPredicates
 
-       syntax.And:    isInteger,
-       syntax.Or:     isInteger,
-       syntax.Xor:    isInteger,
-       syntax.AndNot: isInteger,
+func init() {
+       // Setting binaryOpPredicates in init avoids declaration cycles.
+       binaryOpPredicates = opPredicates{
+               syntax.Add: isNumericOrString,
+               syntax.Sub: isNumeric,
+               syntax.Mul: isNumeric,
+               syntax.Div: isNumeric,
+               syntax.Rem: isInteger,
 
-       syntax.AndAnd: isBoolean,
-       syntax.OrOr:   isBoolean,
+               syntax.And:    isInteger,
+               syntax.Or:     isInteger,
+               syntax.Xor:    isInteger,
+               syntax.AndNot: isInteger,
+
+               syntax.AndAnd: isBoolean,
+               syntax.OrOr:   isBoolean,
+       }
 }
 
 // If e != nil, it must be the binary expression; it may be nil for non-constant expressions
index 1025c18b23bf0db7dc52909eeec0c47894d351a0..52bd99deab6324400ed2084da30b836fe7f708f4 100644 (file)
@@ -881,16 +881,7 @@ func (t *top) String() string       { return TypeString(t, nil) }
 // If it doesn't exist, the result is Typ[Invalid].
 // under must only be called when a type is known
 // to be fully set up.
-//
-// under is set to underf to avoid an initialization cycle.
-// TODO(gri) this doesn't happen in go/types - investigate
-var under func(Type) Type
-
-func init() {
-       under = underf
-}
-
-func underf(t Type) Type {
+func under(t Type) Type {
        // TODO(gri) is this correct for *Sum?
        if n := asNamed(t); n != nil {
                return n.under()