diff options
| author | Mark Freeman <mark@golang.org> | 2026-02-05 16:16:22 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-02-05 14:26:01 -0800 |
| commit | e2a34c7e9b04564ddad50bd7ec7b52fabde74192 (patch) | |
| tree | 9f1c34d55b69dd1bd48af6107231724ae5cc04a0 /src | |
| parent | 934a79ff2f25292798a5a0469fc8b4bddb6dcee7 (diff) | |
| download | go-e2a34c7e9b04564ddad50bd7ec7b52fabde74192.tar.xz | |
go/types, types2: mechanically swap x.mode() == invalid for !x.isValid()
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/types2/assignments.go | 8 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/builtins.go | 36 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/call.go | 10 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/expr.go | 40 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/index.go | 8 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/infer.go | 4 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/literals.go | 4 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/operand.go | 2 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/range.go | 6 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/stmt.go | 18 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types2/typexpr.go | 2 | ||||
| -rw-r--r-- | src/go/types/assignments.go | 8 | ||||
| -rw-r--r-- | src/go/types/builtins.go | 36 | ||||
| -rw-r--r-- | src/go/types/call.go | 10 | ||||
| -rw-r--r-- | src/go/types/expr.go | 40 | ||||
| -rw-r--r-- | src/go/types/index.go | 8 | ||||
| -rw-r--r-- | src/go/types/infer.go | 4 | ||||
| -rw-r--r-- | src/go/types/literals.go | 4 | ||||
| -rw-r--r-- | src/go/types/operand.go | 2 | ||||
| -rw-r--r-- | src/go/types/range.go | 6 | ||||
| -rw-r--r-- | src/go/types/stmt.go | 22 | ||||
| -rw-r--r-- | src/go/types/typexpr.go | 2 |
22 files changed, 140 insertions, 140 deletions
diff --git a/src/cmd/compile/internal/types2/assignments.go b/src/cmd/compile/internal/types2/assignments.go index bd188d51da..f4ad4938ac 100644 --- a/src/cmd/compile/internal/types2/assignments.go +++ b/src/cmd/compile/internal/types2/assignments.go @@ -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] } diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go index c975767fc6..45b0f41a5e 100644 --- a/src/cmd/compile/internal/types2/builtins.go +++ b/src/cmd/compile/internal/types2/builtins.go @@ -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 } diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go index 467dc37609..21f929642a 100644 --- a/src/cmd/compile/internal/types2/call.go +++ b/src/cmd/compile/internal/types2/call.go @@ -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() } diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index b092e74b0f..4f2f6b4431 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -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 { diff --git a/src/cmd/compile/internal/types2/index.go b/src/cmd/compile/internal/types2/index.go index 054def5402..fd92bef2cb 100644 --- a/src/cmd/compile/internal/types2/index.go +++ b/src/cmd/compile/internal/types2/index.go @@ -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 } diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index 3aeace192e..c57289622f 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -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. diff --git a/src/cmd/compile/internal/types2/literals.go b/src/cmd/compile/internal/types2/literals.go index e33efd93ea..04a138c55b 100644 --- a/src/cmd/compile/internal/types2/literals.go +++ b/src/cmd/compile/internal/types2/literals.go @@ -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_ { diff --git a/src/cmd/compile/internal/types2/operand.go b/src/cmd/compile/internal/types2/operand.go index 83066c0e30..0e8aa24163 100644 --- a/src/cmd/compile/internal/types2/operand.go +++ b/src/cmd/compile/internal/types2/operand.go @@ -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 } diff --git a/src/cmd/compile/internal/types2/range.go b/src/cmd/compile/internal/types2/range.go index 1135066af8..ae6524d0e4 100644 --- a/src/cmd/compile/internal/types2/range.go +++ b/src/cmd/compile/internal/types2/range.go @@ -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 { diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index 1da8afb238..1c373299e3 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -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()) { diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index 8453e2d5eb..bffc9ba684 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -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 diff --git a/src/go/types/assignments.go b/src/go/types/assignments.go index 5655ea0b10..fcb39e3223 100644 --- a/src/go/types/assignments.go +++ b/src/go/types/assignments.go @@ -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] } diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index 1f55368826..7f7b07166a 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -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 } diff --git a/src/go/types/call.go b/src/go/types/call.go index 0b8ef351db..744f246d24 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -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() } diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 344246e741..ad8bad2fe7 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -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 { diff --git a/src/go/types/index.go b/src/go/types/index.go index 8a540151cb..3c8bf4ffe4 100644 --- a/src/go/types/index.go +++ b/src/go/types/index.go @@ -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 } diff --git a/src/go/types/infer.go b/src/go/types/infer.go index 6a49be7079..6a7364e246 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -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. diff --git a/src/go/types/literals.go b/src/go/types/literals.go index bc98ae8db0..04fe103019 100644 --- a/src/go/types/literals.go +++ b/src/go/types/literals.go @@ -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_ { diff --git a/src/go/types/operand.go b/src/go/types/operand.go index 66850d67d6..860611ac89 100644 --- a/src/go/types/operand.go +++ b/src/go/types/operand.go @@ -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 } diff --git a/src/go/types/range.go b/src/go/types/range.go index 05ef827eec..208da64ba2 100644 --- a/src/go/types/range.go +++ b/src/go/types/range.go @@ -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 { diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index 773c2fd590..e856c5e712 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -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") } } diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index c718922572..f289844f33 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -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 |
