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/cmd | |
| 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/cmd')
| -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 |
11 files changed, 69 insertions, 69 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 |
