]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: mechanically swap x.mode() == invalid for !x.isValid()
authorMark Freeman <mark@golang.org>
Thu, 5 Feb 2026 21:16:22 +0000 (16:16 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 5 Feb 2026 22:26:01 +0000 (14:26 -0800)
Change-Id: I2e98178a42ad225aa3803dc4ccd26d50938f29b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/742501
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>

22 files changed:
src/cmd/compile/internal/types2/assignments.go
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/index.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/literals.go
src/cmd/compile/internal/types2/operand.go
src/cmd/compile/internal/types2/range.go
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/typexpr.go
src/go/types/assignments.go
src/go/types/builtins.go
src/go/types/call.go
src/go/types/expr.go
src/go/types/index.go
src/go/types/infer.go
src/go/types/literals.go
src/go/types/operand.go
src/go/types/range.go
src/go/types/stmt.go
src/go/types/typexpr.go

index bd188d51da6c92683850603a0e9403e92a0e804c..f4ad4938ac63df4e7a1b9c86dba163bbf424e727 100644 (file)
@@ -116,7 +116,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
 }
 
 func (check *Checker) initConst(lhs *Const, x *operand) {
-       if x.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) {
+       if !x.isValid() || !isValid(x.typ()) || !isValid(lhs.typ) {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -139,7 +139,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
        }
 
        check.assignment(x, lhs.typ, "constant declaration")
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
 
@@ -151,7 +151,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
 // or Typ[Invalid] in case of an error.
 // If the initialization check fails, x.mode is set to invalid.
 func (check *Checker) initVar(lhs *Var, x *operand, context string) {
-       if x.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) {
+       if !x.isValid() || !isValid(x.typ()) || !isValid(lhs.typ) {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -216,7 +216,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
                check.usedVars[v] = v_used // restore v.used
        }
 
-       if x.mode() == invalid || !isValid(x.typ()) {
+       if !x.isValid() || !isValid(x.typ()) {
                return Typ[Invalid]
        }
 
index c975767fc66f4d0c6cfb29e9c681f5042c0caa5d..45b0f41a5e75e223a28b4d393c9c71c05c3e11bc 100644 (file)
@@ -53,7 +53,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                args = check.exprList(argList)
                nargs = len(args)
                for _, a := range args {
-                       if a.mode() == invalid {
+                       if !a.isValid() {
                                return
                        }
                }
@@ -312,7 +312,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                // and check below
                        }
                }
-               if x.mode() == invalid || y.mode() == invalid {
+               if !x.isValid() || !y.isValid() {
                        return
                }
 
@@ -438,7 +438,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
                *x = *args[1] // key
                check.assignment(x, key, "argument to delete")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -466,7 +466,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                // result in an error (shift of complex value)
                                check.convertUntyped(x, Typ[Complex128])
                                // x should be invalid now, but be conservative and check
-                               if x.mode() == invalid {
+                               if !x.isValid() {
                                        return
                                }
                        }
@@ -585,7 +585,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                for i, a := range args {
-                       if a.mode() == invalid {
+                       if !a.isValid() {
                                return
                        }
 
@@ -597,7 +597,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        // The first argument is already in x and there's nothing left to do.
                        if i > 0 {
                                check.matchTypes(x, a)
-                               if x.mode() == invalid {
+                               if !x.isValid() {
                                        return
                                }
 
@@ -621,7 +621,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        x.mode_ = value
                        // A value must not be untyped.
                        check.assignment(x, &emptyInterface, "argument to built-in "+bin.name)
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                return
                        }
                }
@@ -656,7 +656,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        if isUntyped(x.typ()) {
                                // check for overflow and untyped nil
                                check.assignment(x, nil, "argument to new")
-                               if x.mode() == invalid {
+                               if !x.isValid() {
                                        return
                                }
                                assert(isTyped(x.typ()))
@@ -688,7 +688,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                check.assignment(x, &emptyInterface, "argument to panic")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -705,7 +705,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        params = make([]Type, nargs)
                        for i, a := range args {
                                check.assignment(a, nil, "argument to built-in "+predeclaredFuncs[id].name)
-                               if a.mode() == invalid {
+                               if !a.isValid() {
                                        return
                                }
                                params[i] = a.typ()
@@ -730,7 +730,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                check.verifyVersionf(call.Fun, go1_17, "unsafe.Add")
 
                check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -748,7 +748,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
        case _Alignof:
                // unsafe.Alignof(x T) uintptr
                check.assignment(x, nil, "argument to unsafe.Alignof")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -776,7 +776,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                check.expr(nil, x, selx.X)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -836,7 +836,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
        case _Sizeof:
                // unsafe.Sizeof(x T) uintptr
                check.assignment(x, nil, "argument to unsafe.Sizeof")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -901,7 +901,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                check.verifyVersionf(call.Fun, go1_20, "unsafe.String")
 
                check.assignment(x, NewPointer(universeByte), "argument to unsafe.String")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -921,7 +921,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                check.verifyVersionf(call.Fun, go1_20, "unsafe.StringData")
 
                check.assignment(x, Typ[String], "argument to unsafe.StringData")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -967,7 +967,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        check.dump("%v: %s", atPos(x1), x1)
                        x1 = &t // use incoming x only for first argument
                }
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
                // trace is only available in test mode - no need to record signature
@@ -976,7 +976,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                panic("unreachable")
        }
 
-       assert(x.mode() != invalid)
+       assert(x.isValid())
        return true
 }
 
index 467dc376094f591b5e2ac31caf469ac53aa58c99..21f929642a399d8ba7d43f3cd99ae27630291bda 100644 (file)
@@ -194,7 +194,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
        case typexpr:
                // conversion
                check.nonGeneric(nil, x)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return conversion
                }
                T := x.typ()
@@ -209,7 +209,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                        check.errorf(call, WrongArgCount, "missing argument in conversion to %s", T)
                case 1:
                        check.expr(nil, x, call.ArgList[0])
-                       if x.mode() != invalid {
+                       if x.isValid() {
                                if t, _ := T.Underlying().(*Interface); t != nil && !isTypeParam(T) {
                                        if !t.IsMethodSet() {
                                                check.errorf(call, MisplacedConstraintIface, "cannot use interface %s in conversion (contains specific type constraints or is comparable)", T)
@@ -237,7 +237,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                }
                x.expr = call
                // a non-constant result implies a function call
-               if x.mode() != invalid && x.mode() != constant_ {
+               if x.isValid() && x.mode() != constant_ {
                        check.hasCallOrRecv = true
                }
                return predeclaredFuncs[id].kind
@@ -417,7 +417,7 @@ func (check *Checker) genericExprList(elist []syntax.Expr) (resList []*operand,
                        // x is not a function instantiation (it may still be a generic function).
                        check.rawExpr(nil, &x, e, nil, true)
                        check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
-                       if t, ok := x.typ().(*Tuple); ok && x.mode() != invalid {
+                       if t, ok := x.typ().(*Tuple); ok && x.isValid() {
                                // x is a function call returning multiple values; it cannot be generic.
                                resList = make([]*operand, t.Len())
                                for i, v := range t.vars {
@@ -1001,5 +1001,5 @@ func (check *Checker) use1(e syntax.Expr, lhs bool) bool {
        default:
                check.rawExpr(nil, &x, e, nil, true)
        }
-       return x.mode() != invalid
+       return x.isValid()
 }
index b092e74b0fb6e102803909dc27ec4e81cd21622c..4f2f6b4431f768e91656084a4980669d1757a03d 100644 (file)
@@ -129,7 +129,7 @@ var op2str2 = [...]string{
 
 func (check *Checker) unary(x *operand, e *syntax.Operation) {
        check.expr(nil, x, e.X)
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
 
@@ -387,7 +387,7 @@ func (check *Checker) updateExprType(x syntax.Expr, typ Type, final bool) {
                // If x is a constant, it must be representable as a value of typ.
                c := operand{old.mode, x, old.typ, old.val, 0}
                check.convertUntyped(&c, typ)
-               if c.mode() == invalid {
+               if !c.isValid() {
                        return
                }
        }
@@ -411,7 +411,7 @@ func (check *Checker) updateExprVal(x syntax.Expr, val constant.Value) {
 // If x is a constant operand, the returned constant.Value will be the
 // representation of x in this context.
 func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, constant.Value, Code) {
-       if x.mode() == invalid || isTyped(x.typ()) || !isValid(target) {
+       if !x.isValid() || isTyped(x.typ()) || !isValid(target) {
                return x.typ(), nil, 0
        }
        // x is untyped
@@ -663,7 +663,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                        // Caution: Check for representability here, rather than in the switch
                        // below, because isInteger includes untyped integers (was bug go.dev/issue/43697).
                        check.representable(y, Typ[Uint])
-                       if y.mode() == invalid {
+                       if !y.isValid() {
                                x.invalidate()
                                return
                        }
@@ -680,7 +680,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                        // This is incorrect, but preserves pre-existing behavior.
                        // See also go.dev/issue/47410.
                        check.convertUntyped(y, Typ[Uint])
-                       if y.mode() == invalid {
+                       if !y.isValid() {
                                x.invalidate()
                                return
                        }
@@ -794,10 +794,10 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
        check.expr(nil, x, lhs)
        check.expr(nil, &y, rhs)
 
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
-       if y.mode() == invalid {
+       if !y.isValid() {
                x.invalidate()
                x.expr = y.expr
                return
@@ -809,7 +809,7 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
        }
 
        check.matchTypes(x, &y)
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
 
@@ -932,11 +932,11 @@ func (check *Checker) matchTypes(x, y *operand) {
 
        if mayConvert(x, y) {
                check.convertUntyped(x, y.typ())
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
                check.convertUntyped(y, x.typ())
-               if y.mode() == invalid {
+               if !y.isValid() {
                        x.invalidate()
                        return
                }
@@ -1003,7 +1003,7 @@ func (check *Checker) rawExpr(T *target, x *operand, e syntax.Expr, hint Type, a
 // from a non-nil target T, nonGeneric reports an error and invalidates x.mode and x.typ.
 // Otherwise it leaves x alone.
 func (check *Checker) nonGeneric(T *target, x *operand) {
-       if x.mode() == invalid || x.mode() == novalue {
+       if !x.isValid() || x.mode() == novalue {
                return
        }
        var what string
@@ -1057,19 +1057,19 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                        goto Error // error reported during parsing
                }
                check.basicLit(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *syntax.FuncLit:
                check.funcLit(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *syntax.CompositeLit:
                check.compositeLit(x, e, hint)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
@@ -1089,19 +1089,19 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                        }
                        check.funcInst(T, e.Pos(), x, e, true)
                }
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *syntax.SliceExpr:
                check.sliceExpr(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *syntax.AssertExpr:
                check.expr(nil, x, e.X)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
                // x.(type) expressions are encoded via TypeSwitchGuards
@@ -1203,7 +1203,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                        }
 
                        check.unary(x, e)
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                goto Error
                        }
                        if e.Op == syntax.Recv {
@@ -1215,7 +1215,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
 
                // binary expression
                check.binary(x, e, e.X, e.Y, e.Op)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
@@ -1333,7 +1333,7 @@ func (check *Checker) multiExpr(e syntax.Expr, allowCommaOk bool) (list []*opera
        check.rawExpr(nil, &x, e, nil, false)
        check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
 
-       if t, ok := x.typ().(*Tuple); ok && x.mode() != invalid {
+       if t, ok := x.typ().(*Tuple); ok && x.isValid() {
                // multiple values
                list = make([]*operand, t.Len())
                for i, v := range t.vars {
index 054def5402a4e2bca8c8ac292c2ea38ead9ba16d..fd92bef2cb1206935930d9b6f1411e3280ad8cdf 100644 (file)
@@ -43,7 +43,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
 
        // x should not be generic at this point, but be safe and check
        check.nonGeneric(nil, x)
-       if x.mode() == invalid {
+       if !x.isValid() {
                return false
        }
 
@@ -230,7 +230,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
 
 func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
        check.expr(nil, x, e.X)
-       if x.mode() == invalid {
+       if !x.isValid() {
                check.use(e.Index[:]...)
                return
        }
@@ -451,13 +451,13 @@ func (check *Checker) index(index syntax.Expr, max int64) (typ Type, val int64)
 // If the operand is not valid, an error is reported (using what as context)
 // and the result is false.
 func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNegative bool) bool {
-       if x.mode() == invalid {
+       if !x.isValid() {
                return false
        }
 
        // spec: "a constant index that is untyped is given type int"
        check.convertUntyped(x, Typ[Int])
-       if x.mode() == invalid {
+       if !x.isValid() {
                return false
        }
 
index 3aeace192e41b3c84066f760811a78391a926ca8..c57289622fbe1617fbe376b13d674895a0c37004 100644 (file)
@@ -62,7 +62,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        // If we have invalid (ordinary) arguments, an error was reported before.
        // Avoid additional inference errors and exit early (go.dev/issue/60434).
        for _, arg := range args {
-               if arg.mode() == invalid {
+               if !arg.isValid() {
                        return nil
                }
        }
@@ -162,7 +162,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        }
 
        for i, arg := range args {
-               if arg.mode() == invalid {
+               if !arg.isValid() {
                        // An error was reported earlier. Ignore this arg
                        // and continue, we may still be able to infer all
                        // targs resulting in fewer follow-on errors.
index e33efd93eae88d9022df61355eb3cbb295d9fcda..04a138c55b9183a8e61454a3daf50198e8b39b45 100644 (file)
@@ -62,7 +62,7 @@ func (check *Checker) basicLit(x *operand, e *syntax.BasicLit) {
                }
        }
        x.setConst(e.Kind, e.Value)
-       if x.mode() == invalid {
+       if !x.isValid() {
                // The parser already establishes syntactic correctness.
                // If we reach here it's because of number under-/overflow.
                // TODO(gri) setConst (and in turn the go/constant package)
@@ -261,7 +261,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
                        }
                        check.exprWithHint(x, kv.Key, utyp.key)
                        check.assignment(x, utyp.key, "map literal")
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                continue
                        }
                        if x.mode() == constant_ {
index 83066c0e3011ab99eacfce064008a993c96dfa01..0e8aa24163cbab280c44d6d903d513c9aaea1348 100644 (file)
@@ -322,7 +322,7 @@ func (x *operand) isNil() bool {
 // if assignableTo is invoked through an exported API call, i.e., when all
 // methods have been type-checked.
 func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Code) {
-       if x.mode() == invalid || !isValid(T) {
+       if !x.isValid() || !isValid(T) {
                return true, 0 // avoid spurious errors
        }
 
index 1135066af8626397bd5bc4f9f0084d2cf0b55e91..ae6524d0e4b1edd7f2dff2c5d7fb6bbf84b62f10 100644 (file)
@@ -34,7 +34,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
        check.hasCallOrRecv = false
        check.expr(nil, &x, rangeVar)
 
-       if isTypes2 && x.mode() != invalid && sValue == nil && !check.hasCallOrRecv {
+       if isTypes2 && x.isValid() && sValue == nil && !check.hasCallOrRecv {
                if t, ok := arrayPtrDeref(x.typ().Underlying()).(*Array); ok {
                        for {
                                // Put constant info on the thing inside parentheses.
@@ -61,7 +61,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
 
        // determine key/value types
        var key, val Type
-       if x.mode() != invalid {
+       if x.isValid() {
                k, v, cause, ok := rangeKeyVal(check, x.typ(), func(v goVersion) bool {
                        return check.allowVersion(v)
                })
@@ -169,7 +169,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
                                // If the assignment succeeded, if x was untyped before, it now
                                // has a type inferred via the assignment. It must be an integer.
                                // (go.dev/issues/67027)
-                               if x.mode() != invalid && !isInteger(x.typ()) {
+                               if x.isValid() && !isInteger(x.typ()) {
                                        check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ())
                                }
                        } else {
index 1da8afb23895ec0b4319f6912bc39fa4bb0db8da..1c373299e39a3736f5aac14b17ade49fb2d5f109 100644 (file)
@@ -238,17 +238,17 @@ L:
        for _, e := range values {
                var v operand
                check.expr(nil, &v, e)
-               if x.mode() == invalid || v.mode() == invalid {
+               if !x.isValid() || !v.isValid() {
                        continue L
                }
                check.convertUntyped(&v, x.typ())
-               if v.mode() == invalid {
+               if !v.isValid() {
                        continue L
                }
                // Order matters: By comparing v against x, error positions are at the case values.
                res := v // keep original v unchanged
                check.comparison(&res, x, syntax.Eql, true)
-               if res.mode() == invalid {
+               if !res.isValid() {
                        continue L
                }
                if v.mode() != constant_ {
@@ -464,7 +464,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
                var ch, val operand
                check.expr(nil, &ch, s.Chan)
                check.expr(nil, &val, s.Value)
-               if ch.mode() == invalid || val.mode() == invalid {
+               if !ch.isValid() || !val.isValid() {
                        return
                }
                if elem := check.chanElem(s, &ch, false); elem != nil {
@@ -477,7 +477,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
                        // (no need to call unpackExpr as s.Lhs must be single-valued)
                        var x operand
                        check.expr(nil, &x, s.Lhs)
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                return
                        }
                        if !allNumeric(x.typ()) {
@@ -592,7 +592,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
                check.simpleStmt(s.Init)
                var x operand
                check.expr(nil, &x, s.Cond)
-               if x.mode() != invalid && !allBoolean(x.typ()) {
+               if x.isValid() && !allBoolean(x.typ()) {
                        check.error(s.Cond, InvalidCond, "non-boolean condition in if statement")
                }
                check.stmt(inner, s.Then)
@@ -694,7 +694,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
                if s.Cond != nil {
                        var x operand
                        check.expr(nil, &x, s.Cond)
-                       if x.mode() != invalid && !allBoolean(x.typ()) {
+                       if x.isValid() && !allBoolean(x.typ()) {
                                check.error(s.Cond, InvalidCond, "non-boolean condition in for statement")
                        }
                }
@@ -721,7 +721,7 @@ func (check *Checker) switchStmt(inner stmtContext, s *syntax.SwitchStmt) {
                // By checking assignment of x to an invisible temporary
                // (as a compiler would), we get all the relevant checks.
                check.assignment(&x, nil, "switch expression")
-               if x.mode() != invalid && !Comparable(x.typ()) && !hasNil(x.typ()) {
+               if x.isValid() && !Comparable(x.typ()) && !hasNil(x.typ()) {
                        check.errorf(&x, InvalidExprSwitch, "cannot switch on %s (%s is not comparable)", &x, x.typ())
                        x.invalidate()
                }
@@ -785,7 +785,7 @@ func (check *Checker) typeSwitchStmt(inner stmtContext, s *syntax.SwitchStmt, gu
        {
                var x operand
                check.expr(nil, &x, guard.X)
-               if x.mode() != invalid {
+               if x.isValid() {
                        if isTypeParam(x.typ()) {
                                check.errorf(&x, InvalidTypeSwitch, "cannot use type switch on type parameter value %s", &x)
                        } else if IsInterface(x.typ()) {
index 8453e2d5eb93ae29fc3b78c6432c469f1e491b82..bffc9ba684eb45c125e02917df33388889e45ca7 100644 (file)
@@ -483,7 +483,7 @@ func (check *Checker) arrayLength(e syntax.Expr) int64 {
        var x operand
        check.expr(nil, &x, e)
        if x.mode() != constant_ {
-               if x.mode() != invalid {
+               if x.isValid() {
                        check.errorf(&x, InvalidArrayLen, "array length %s must be constant", &x)
                }
                return -1
index 5655ea0b10ea10ef10917eb1ef8d92aad52d8c14..fcb39e322345a12163b7d280c65ef204a2206062 100644 (file)
@@ -119,7 +119,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
 }
 
 func (check *Checker) initConst(lhs *Const, x *operand) {
-       if x.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) {
+       if !x.isValid() || !isValid(x.typ()) || !isValid(lhs.typ) {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -142,7 +142,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
        }
 
        check.assignment(x, lhs.typ, "constant declaration")
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
 
@@ -154,7 +154,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
 // or Typ[Invalid] in case of an error.
 // If the initialization check fails, x.mode is set to invalid.
 func (check *Checker) initVar(lhs *Var, x *operand, context string) {
-       if x.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) {
+       if !x.isValid() || !isValid(x.typ()) || !isValid(lhs.typ) {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -219,7 +219,7 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type {
                check.usedVars[v] = v_used // restore v.used
        }
 
-       if x.mode() == invalid || !isValid(x.typ()) {
+       if !x.isValid() || !isValid(x.typ()) {
                return Typ[Invalid]
        }
 
index 1f5536882693d7be91a943abf732bb690f7288d2..7f7b07166ade893ad0b17e58af8de1560fc9bb16 100644 (file)
@@ -56,7 +56,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                args = check.exprList(argList)
                nargs = len(args)
                for _, a := range args {
-                       if a.mode() == invalid {
+                       if !a.isValid() {
                                return
                        }
                }
@@ -315,7 +315,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                // and check below
                        }
                }
-               if x.mode() == invalid || y.mode() == invalid {
+               if !x.isValid() || !y.isValid() {
                        return
                }
 
@@ -441,7 +441,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
                *x = *args[1] // key
                check.assignment(x, key, "argument to delete")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -469,7 +469,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                // result in an error (shift of complex value)
                                check.convertUntyped(x, Typ[Complex128])
                                // x should be invalid now, but be conservative and check
-                               if x.mode() == invalid {
+                               if !x.isValid() {
                                        return
                                }
                        }
@@ -588,7 +588,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                for i, a := range args {
-                       if a.mode() == invalid {
+                       if !a.isValid() {
                                return
                        }
 
@@ -600,7 +600,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        // The first argument is already in x and there's nothing left to do.
                        if i > 0 {
                                check.matchTypes(x, a)
-                               if x.mode() == invalid {
+                               if !x.isValid() {
                                        return
                                }
 
@@ -624,7 +624,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        x.mode_ = value
                        // A value must not be untyped.
                        check.assignment(x, &emptyInterface, "argument to built-in "+bin.name)
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                return
                        }
                }
@@ -659,7 +659,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        if isUntyped(x.typ()) {
                                // check for overflow and untyped nil
                                check.assignment(x, nil, "argument to new")
-                               if x.mode() == invalid {
+                               if !x.isValid() {
                                        return
                                }
                                assert(isTyped(x.typ()))
@@ -691,7 +691,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                check.assignment(x, &emptyInterface, "argument to panic")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -708,7 +708,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        params = make([]Type, nargs)
                        for i, a := range args {
                                check.assignment(a, nil, "argument to built-in "+predeclaredFuncs[id].name)
-                               if a.mode() == invalid {
+                               if !a.isValid() {
                                        return
                                }
                                params[i] = a.typ()
@@ -733,7 +733,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                check.verifyVersionf(call.Fun, go1_17, "unsafe.Add")
 
                check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -751,7 +751,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        case _Alignof:
                // unsafe.Alignof(x T) uintptr
                check.assignment(x, nil, "argument to unsafe.Alignof")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -779,7 +779,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                check.expr(nil, x, selx.X)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -839,7 +839,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        case _Sizeof:
                // unsafe.Sizeof(x T) uintptr
                check.assignment(x, nil, "argument to unsafe.Sizeof")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -904,7 +904,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                check.verifyVersionf(call.Fun, go1_20, "unsafe.String")
 
                check.assignment(x, NewPointer(universeByte), "argument to unsafe.String")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -924,7 +924,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                check.verifyVersionf(call.Fun, go1_20, "unsafe.StringData")
 
                check.assignment(x, Typ[String], "argument to unsafe.StringData")
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
 
@@ -970,7 +970,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        check.dump("%v: %s", x1.Pos(), x1)
                        x1 = &t // use incoming x only for first argument
                }
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
                // trace is only available in test mode - no need to record signature
@@ -979,7 +979,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                panic("unreachable")
        }
 
-       assert(x.mode() != invalid)
+       assert(x.isValid())
        return true
 }
 
index 0b8ef351db94c48197990e8c483c5153f15a1f88..744f246d24f5410466ae09d6b53a46572eb84e27 100644 (file)
@@ -196,7 +196,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
        case typexpr:
                // conversion
                check.nonGeneric(nil, x)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return conversion
                }
                T := x.typ()
@@ -211,7 +211,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
                        check.errorf(inNode(call, call.Rparen), WrongArgCount, "missing argument in conversion to %s", T)
                case 1:
                        check.expr(nil, x, call.Args[0])
-                       if x.mode() != invalid {
+                       if x.isValid() {
                                if hasDots(call) {
                                        check.errorf(call.Args[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
                                        break
@@ -239,7 +239,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
                }
                x.expr = call
                // a non-constant result implies a function call
-               if x.mode() != invalid && x.mode() != constant_ {
+               if x.isValid() && x.mode() != constant_ {
                        check.hasCallOrRecv = true
                }
                return predeclaredFuncs[id].kind
@@ -419,7 +419,7 @@ func (check *Checker) genericExprList(elist []ast.Expr) (resList []*operand, tar
                        // x is not a function instantiation (it may still be a generic function).
                        check.rawExpr(nil, &x, e, nil, true)
                        check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
-                       if t, ok := x.typ().(*Tuple); ok && x.mode() != invalid {
+                       if t, ok := x.typ().(*Tuple); ok && x.isValid() {
                                // x is a function call returning multiple values; it cannot be generic.
                                resList = make([]*operand, t.Len())
                                for i, v := range t.vars {
@@ -1047,5 +1047,5 @@ func (check *Checker) use1(e ast.Expr, lhs bool) bool {
        default:
                check.rawExpr(nil, &x, e, nil, true)
        }
-       return x.mode() != invalid
+       return x.isValid()
 }
index 344246e74130e91fe6585c7203b2d844c29e5f0a..ad8bad2fe7b954b22a18046f0a338654aa2ca7d6 100644 (file)
@@ -128,7 +128,7 @@ var op2str2 = [...]string{
 // The unary expression e may be nil. It's passed in for better error messages only.
 func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
        check.expr(nil, x, e.X)
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
 
@@ -362,7 +362,7 @@ func (check *Checker) updateExprType(x ast.Expr, typ Type, final bool) {
                // If x is a constant, it must be representable as a value of typ.
                c := operand{old.mode, x, old.typ, old.val, 0}
                check.convertUntyped(&c, typ)
-               if c.mode() == invalid {
+               if !c.isValid() {
                        return
                }
        }
@@ -386,7 +386,7 @@ func (check *Checker) updateExprVal(x ast.Expr, val constant.Value) {
 // If x is a constant operand, the returned constant.Value will be the
 // representation of x in this context.
 func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, constant.Value, Code) {
-       if x.mode() == invalid || isTyped(x.typ()) || !isValid(target) {
+       if !x.isValid() || isTyped(x.typ()) || !isValid(target) {
                return x.typ(), nil, 0
        }
        // x is untyped
@@ -652,7 +652,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                        // Caution: Check for representability here, rather than in the switch
                        // below, because isInteger includes untyped integers (was bug go.dev/issue/43697).
                        check.representable(y, Typ[Uint])
-                       if y.mode() == invalid {
+                       if !y.isValid() {
                                x.invalidate()
                                return
                        }
@@ -669,7 +669,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                        // This is incorrect, but preserves pre-existing behavior.
                        // See also go.dev/issue/47410.
                        check.convertUntyped(y, Typ[Uint])
-                       if y.mode() == invalid {
+                       if !y.isValid() {
                                x.invalidate()
                                return
                        }
@@ -783,10 +783,10 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
        check.expr(nil, x, lhs)
        check.expr(nil, &y, rhs)
 
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
-       if y.mode() == invalid {
+       if !y.isValid() {
                x.invalidate()
                x.expr = y.expr
                return
@@ -798,7 +798,7 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
        }
 
        check.matchTypes(x, &y)
-       if x.mode() == invalid {
+       if !x.isValid() {
                return
        }
 
@@ -924,11 +924,11 @@ func (check *Checker) matchTypes(x, y *operand) {
 
        if mayConvert(x, y) {
                check.convertUntyped(x, y.typ())
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
                check.convertUntyped(y, x.typ())
-               if y.mode() == invalid {
+               if !y.isValid() {
                        x.invalidate()
                        return
                }
@@ -995,7 +995,7 @@ func (check *Checker) rawExpr(T *target, x *operand, e ast.Expr, hint Type, allo
 // from a non-nil target T, nonGeneric reports an error and invalidates x.mode and x.typ.
 // Otherwise it leaves x alone.
 func (check *Checker) nonGeneric(T *target, x *operand) {
-       if x.mode() == invalid || x.mode() == novalue {
+       if !x.isValid() || x.mode() == novalue {
                return
        }
        var what string
@@ -1043,19 +1043,19 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
 
        case *ast.BasicLit:
                check.basicLit(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *ast.FuncLit:
                check.funcLit(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *ast.CompositeLit:
                check.compositeLit(x, e, hint)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
@@ -1076,19 +1076,19 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
                        }
                        check.funcInst(T, e.Pos(), x, ix, true)
                }
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *ast.SliceExpr:
                check.sliceExpr(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
        case *ast.TypeAssertExpr:
                check.expr(nil, x, e.X)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
                // x.(type) expressions are handled explicitly in type switches
@@ -1156,7 +1156,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
 
        case *ast.UnaryExpr:
                check.unary(x, e)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
                if e.Op == token.ARROW {
@@ -1166,7 +1166,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
 
        case *ast.BinaryExpr:
                check.binary(x, e, e.X, e.Y, e.Op, e.OpPos)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        goto Error
                }
 
@@ -1284,7 +1284,7 @@ func (check *Checker) multiExpr(e ast.Expr, allowCommaOk bool) (list []*operand,
        check.rawExpr(nil, &x, e, nil, false)
        check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
 
-       if t, ok := x.typ().(*Tuple); ok && x.mode() != invalid {
+       if t, ok := x.typ().(*Tuple); ok && x.isValid() {
                // multiple values
                list = make([]*operand, t.Len())
                for i, v := range t.vars {
index 8a540151cb7aaf8ab19d4c5e4ddc91bc8f9e7bff..3c8bf4ffe41b4632b5b119f5f86d99d849038d9b 100644 (file)
@@ -44,7 +44,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
 
        // x should not be generic at this point, but be safe and check
        check.nonGeneric(nil, x)
-       if x.mode() == invalid {
+       if !x.isValid() {
                return false
        }
 
@@ -232,7 +232,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
 
 func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
        check.expr(nil, x, e.X)
-       if x.mode() == invalid {
+       if !x.isValid() {
                check.use(e.Low, e.High, e.Max)
                return
        }
@@ -447,13 +447,13 @@ func (check *Checker) index(index ast.Expr, max int64) (typ Type, val int64) {
 }
 
 func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNegative bool) bool {
-       if x.mode() == invalid {
+       if !x.isValid() {
                return false
        }
 
        // spec: "a constant index that is untyped is given type int"
        check.convertUntyped(x, Typ[Int])
-       if x.mode() == invalid {
+       if !x.isValid() {
                return false
        }
 
index 6a49be707934feb0f1ee5d22a1a73f94cc381fc1..6a7364e246ea3864124404cb492b6a92ea797afe 100644 (file)
@@ -65,7 +65,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
        // If we have invalid (ordinary) arguments, an error was reported before.
        // Avoid additional inference errors and exit early (go.dev/issue/60434).
        for _, arg := range args {
-               if arg.mode() == invalid {
+               if !arg.isValid() {
                        return nil
                }
        }
@@ -165,7 +165,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
        }
 
        for i, arg := range args {
-               if arg.mode() == invalid {
+               if !arg.isValid() {
                        // An error was reported earlier. Ignore this arg
                        // and continue, we may still be able to infer all
                        // targs resulting in fewer follow-on errors.
index bc98ae8db0e47c037609162f97c04701c2c70856..04fe103019a395db492b52fb4915a26749b03827 100644 (file)
@@ -66,7 +66,7 @@ func (check *Checker) basicLit(x *operand, e *ast.BasicLit) {
                }
        }
        x.setConst(e.Kind, e.Value)
-       if x.mode() == invalid {
+       if !x.isValid() {
                // The parser already establishes syntactic correctness.
                // If we reach here it's because of number under-/overflow.
                // TODO(gri) setConst (and in turn the go/constant package)
@@ -265,7 +265,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
                        }
                        check.exprWithHint(x, kv.Key, utyp.key)
                        check.assignment(x, utyp.key, "map literal")
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                continue
                        }
                        if x.mode() == constant_ {
index 66850d67d6c6b5cdf674725747048f046cf36986..860611ac894af72dfed5b98cfd63b4c9c47f116c 100644 (file)
@@ -326,7 +326,7 @@ func (x *operand) isNil() bool {
 // if assignableTo is invoked through an exported API call, i.e., when all
 // methods have been type-checked.
 func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Code) {
-       if x.mode() == invalid || !isValid(T) {
+       if !x.isValid() || !isValid(T) {
                return true, 0 // avoid spurious errors
        }
 
index 05ef827eecafb82312d33e5517137b69e7f7060f..208da64ba2f48edaca29c15c437cb8fc907c44ad 100644 (file)
@@ -37,7 +37,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
        check.hasCallOrRecv = false
        check.expr(nil, &x, rangeVar)
 
-       if isTypes2 && x.mode() != invalid && sValue == nil && !check.hasCallOrRecv {
+       if isTypes2 && x.isValid() && sValue == nil && !check.hasCallOrRecv {
                if t, ok := arrayPtrDeref(x.typ().Underlying()).(*Array); ok {
                        for {
                                // Put constant info on the thing inside parentheses.
@@ -64,7 +64,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
 
        // determine key/value types
        var key, val Type
-       if x.mode() != invalid {
+       if x.isValid() {
                k, v, cause, ok := rangeKeyVal(check, x.typ(), func(v goVersion) bool {
                        return check.allowVersion(v)
                })
@@ -172,7 +172,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
                                // If the assignment succeeded, if x was untyped before, it now
                                // has a type inferred via the assignment. It must be an integer.
                                // (go.dev/issues/67027)
-                               if x.mode() != invalid && !isInteger(x.typ()) {
+                               if x.isValid() && !isInteger(x.typ()) {
                                        check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ())
                                }
                        } else {
index 773c2fd590e80900d87deed3fac259e1de5dbd0c..e856c5e712f841a6d08a3a33e813037ecad157a9 100644 (file)
@@ -239,17 +239,17 @@ L:
        for _, e := range values {
                var v operand
                check.expr(nil, &v, e)
-               if x.mode() == invalid || v.mode() == invalid {
+               if !x.isValid() || !v.isValid() {
                        continue L
                }
                check.convertUntyped(&v, x.typ())
-               if v.mode() == invalid {
+               if !v.isValid() {
                        continue L
                }
                // Order matters: By comparing v against x, error positions are at the case values.
                res := v // keep original v unchanged
                check.comparison(&res, x, token.EQL, true)
-               if res.mode() == invalid {
+               if !res.isValid() {
                        continue L
                }
                if v.mode() != constant_ {
@@ -465,7 +465,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                var ch, val operand
                check.expr(nil, &ch, s.Chan)
                check.expr(nil, &val, s.Value)
-               if ch.mode() == invalid || val.mode() == invalid {
+               if !ch.isValid() || !val.isValid() {
                        return
                }
                if elem := check.chanElem(inNode(s, s.Arrow), &ch, false); elem != nil {
@@ -486,7 +486,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
 
                var x operand
                check.expr(nil, &x, s.X)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
                if !allNumeric(x.typ()) {
@@ -496,7 +496,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
 
                Y := &ast.BasicLit{ValuePos: s.X.Pos(), Kind: token.INT, Value: "1"} // use x's position
                check.binary(&x, nil, s.X, Y, op, s.TokPos)
-               if x.mode() == invalid {
+               if !x.isValid() {
                        return
                }
                check.assignVar(s.X, nil, &x, "assignment")
@@ -528,7 +528,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                        }
                        var x operand
                        check.binary(&x, nil, s.Lhs[0], s.Rhs[0], op, s.TokPos)
-                       if x.mode() == invalid {
+                       if !x.isValid() {
                                return
                        }
                        check.assignVar(s.Lhs[0], nil, &x, "assignment")
@@ -609,7 +609,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                check.simpleStmt(s.Init)
                var x operand
                check.expr(nil, &x, s.Cond)
-               if x.mode() != invalid && !allBoolean(x.typ()) {
+               if x.isValid() && !allBoolean(x.typ()) {
                        check.error(s.Cond, InvalidCond, "non-boolean condition in if statement")
                }
                check.stmt(inner, s.Body)
@@ -636,7 +636,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                        // By checking assignment of x to an invisible temporary
                        // (as a compiler would), we get all the relevant checks.
                        check.assignment(&x, nil, "switch expression")
-                       if x.mode() != invalid && !Comparable(x.typ()) && !hasNil(x.typ()) {
+                       if x.isValid() && !Comparable(x.typ()) && !hasNil(x.typ()) {
                                check.errorf(&x, InvalidExprSwitch, "cannot switch on %s (%s is not comparable)", &x, x.typ())
                                x.invalidate()
                        }
@@ -728,7 +728,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                {
                        var x operand
                        check.expr(nil, &x, expr.X)
-                       if x.mode() != invalid {
+                       if x.isValid() {
                                if isTypeParam(x.typ()) {
                                        check.errorf(&x, InvalidTypeSwitch, "cannot use type switch on type parameter value %s", &x)
                                } else if IsInterface(x.typ()) {
@@ -837,7 +837,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                if s.Cond != nil {
                        var x operand
                        check.expr(nil, &x, s.Cond)
-                       if x.mode() != invalid && !allBoolean(x.typ()) {
+                       if x.isValid() && !allBoolean(x.typ()) {
                                check.error(s.Cond, InvalidCond, "non-boolean condition in for statement")
                        }
                }
index c718922572fd47a517e087dfda4658b2686068d4..f289844f3315b6e6456d45ba3f2234365a5567a1 100644 (file)
@@ -479,7 +479,7 @@ func (check *Checker) arrayLength(e ast.Expr) int64 {
        var x operand
        check.expr(nil, &x, e)
        if x.mode() != constant_ {
-               if x.mode() != invalid {
+               if x.isValid() {
                        check.errorf(&x, InvalidArrayLen, "array length %s must be constant", &x)
                }
                return -1