From cd92bae42f78b4ea69ef39d7827fc827230ce0f3 Mon Sep 17 00:00:00 2001 From: Mark Freeman Date: Wed, 4 Feb 2026 16:46:40 -0500 Subject: [PATCH] go/types, types2: mechanically replace read accesses to operand.mode_ Change-Id: Ib832f4f9fde45b1308208f05756960191953e8f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/742081 Reviewed-by: Robert Griesemer Auto-Submit: Mark Freeman LUCI-TryBot-Result: Go LUCI --- .../compile/internal/types2/assignments.go | 24 +++--- src/cmd/compile/internal/types2/builtins.go | 62 ++++++++-------- src/cmd/compile/internal/types2/call.go | 32 ++++---- src/cmd/compile/internal/types2/const.go | 4 +- .../compile/internal/types2/conversions.go | 4 +- src/cmd/compile/internal/types2/expr.go | 74 +++++++++---------- src/cmd/compile/internal/types2/index.go | 24 +++--- src/cmd/compile/internal/types2/infer.go | 4 +- src/cmd/compile/internal/types2/literals.go | 6 +- src/cmd/compile/internal/types2/operand.go | 24 +++--- src/cmd/compile/internal/types2/range.go | 6 +- src/cmd/compile/internal/types2/recording.go | 8 +- src/cmd/compile/internal/types2/stmt.go | 22 +++--- src/cmd/compile/internal/types2/typexpr.go | 8 +- src/go/types/assignments.go | 24 +++--- src/go/types/builtins.go | 62 ++++++++-------- src/go/types/call.go | 34 ++++----- src/go/types/const.go | 4 +- src/go/types/conversions.go | 4 +- src/go/types/expr.go | 74 +++++++++---------- src/go/types/index.go | 24 +++--- src/go/types/infer.go | 4 +- src/go/types/literals.go | 6 +- src/go/types/operand.go | 24 +++--- src/go/types/range.go | 6 +- src/go/types/recording.go | 8 +- src/go/types/stmt.go | 26 +++---- src/go/types/typexpr.go | 8 +- 28 files changed, 309 insertions(+), 301 deletions(-) diff --git a/src/cmd/compile/internal/types2/assignments.go b/src/cmd/compile/internal/types2/assignments.go index 1e00dade6a..5903a5a310 100644 --- a/src/cmd/compile/internal/types2/assignments.go +++ b/src/cmd/compile/internal/types2/assignments.go @@ -21,7 +21,7 @@ import ( func (check *Checker) assignment(x *operand, T Type, context string) { check.singleValue(x) - switch x.mode_ { + switch x.mode() { case invalid: return // error reported before case nilvalue: @@ -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.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) { if lhs.typ == nil { lhs.typ = Typ[Invalid] } @@ -124,7 +124,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) { } // rhs must be a constant - if x.mode_ != constant_ { + if x.mode() != constant_ { check.errorf(x, InvalidConstInit, "%s is not constant", x) 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.mode() == invalid { 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.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) { if lhs.typ == nil { lhs.typ = Typ[Invalid] } @@ -216,13 +216,13 @@ 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.mode() == invalid || !isValid(x.typ()) { return Typ[Invalid] } // spec: "Each left-hand side operand must be addressable, a map index // expression, or the blank identifier. Operands may be parenthesized." - switch x.mode_ { + switch x.mode() { case invalid: return Typ[Invalid] case variable, mapindex: @@ -231,7 +231,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type { if sel, ok := x.expr.(*syntax.SelectorExpr); ok { var op operand check.expr(nil, &op, sel.X) - if op.mode_ == mapindex { + if op.mode() == mapindex { check.errorf(&x, UnaddressableFieldAssign, "cannot assign to struct field %s in map", ExprString(x.expr)) return Typ[Invalid] } @@ -441,7 +441,7 @@ func (check *Checker) initVars(lhs []*Var, orig_rhs []syntax.Expr, returnStmt sy } // Only record comma-ok expression if both initializations succeeded // (go.dev/issue/59371). - if commaOk && rhs[0].mode_ != invalid && rhs[1].mode_ != invalid { + if commaOk && rhs[0].mode() != invalid && rhs[1].mode() != invalid { check.recordCommaOkTypes(orig_rhs[0], rhs) } return @@ -449,7 +449,7 @@ func (check *Checker) initVars(lhs []*Var, orig_rhs []syntax.Expr, returnStmt sy // In all other cases we have an assignment mismatch. // Only report a mismatch error if there are no other errors on the rhs. - if rhs[0].mode_ != invalid { + if rhs[0].mode() != invalid { if returnStmt != nil { check.returnError(returnStmt, lhs, rhs) } else { @@ -505,7 +505,7 @@ func (check *Checker) assignVars(lhs, orig_rhs []syntax.Expr) { } // Only record comma-ok expression if both assignments succeeded // (go.dev/issue/59371). - if commaOk && rhs[0].mode_ != invalid && rhs[1].mode_ != invalid { + if commaOk && rhs[0].mode() != invalid && rhs[1].mode() != invalid { check.recordCommaOkTypes(orig_rhs[0], rhs) } return @@ -513,7 +513,7 @@ func (check *Checker) assignVars(lhs, orig_rhs []syntax.Expr) { // In all other cases we have an assignment mismatch. // Only report a mismatch error if there are no other errors on the rhs. - if rhs[0].mode_ != invalid { + if rhs[0].mode() != invalid { check.assignError(orig_rhs, l, r) } check.useLHS(lhs...) diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go index f64758a92b..c975767fc6 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.mode() == invalid { return } } @@ -151,7 +151,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( switch t := arrayPtrDeref(x.typ().Underlying()).(type) { case *Basic: if isString(t) && id == _Len { - if x.mode_ == constant_ { + if x.mode() == constant_ { mode = constant_ val = constant.MakeInt64(int64(len(constant.StringVal(x.val)))) } else { @@ -297,7 +297,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( // both of them to float64 since they must have the // same type to succeed (this will result in an error // because shifts of floats are not permitted) - if x.mode_ == constant_ && y.mode_ == constant_ { + if x.mode() == constant_ && y.mode() == constant_ { toFloat := func(x *operand) { if isNumeric(x.typ()) && constant.Sign(constant.Imag(x.val)) == 0 { x.typ_ = Typ[UntypedFloat] @@ -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.mode() == invalid || y.mode() == invalid { return } @@ -345,13 +345,13 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( } // if both arguments are constants, the result is a constant - if x.mode_ == constant_ && y.mode_ == constant_ { + if x.mode() == constant_ && y.mode() == constant_ { x.val = constant.BinaryOp(constant.ToFloat(x.val), token.ADD, constant.MakeImag(constant.ToFloat(y.val))) } else { x.mode_ = value } - if check.recordTypes() && x.mode_ != constant_ { + if check.recordTypes() && x.mode() != constant_ { check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ(), x.typ())) } @@ -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.mode() == invalid { return } @@ -453,7 +453,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( // convert or check untyped argument if isUntyped(x.typ()) { - if x.mode_ == constant_ { + if x.mode() == constant_ { // an untyped constant number can always be considered // as a complex constant if isNumeric(x.typ()) { @@ -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.mode() == invalid { return } } @@ -499,7 +499,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( } // if the argument is a constant, the result is a constant - if x.mode_ == constant_ { + if x.mode() == constant_ { if id == _Real { x.val = constant.Real(x.val) } else { @@ -509,7 +509,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( x.mode_ = value } - if check.recordTypes() && x.mode_ != constant_ { + if check.recordTypes() && x.mode() != constant_ { check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ())) } @@ -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.mode() == invalid { 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.mode() == invalid { return } @@ -606,7 +606,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( return } - if x.mode_ == constant_ && a.mode_ == constant_ { + if x.mode() == constant_ && a.mode() == constant_ { if constant.Compare(a.val, op, x.val) { *x = *a } @@ -617,11 +617,11 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( } // If nargs == 1, make sure x.mode is either a value or a constant. - if x.mode_ != constant_ { + if x.mode() != constant_ { 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.mode() == invalid { return } } @@ -631,7 +631,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( check.updateExprType(a.expr, x.typ(), true) } - if check.recordTypes() && x.mode_ != constant_ { + if check.recordTypes() && x.mode() != constant_ { types := make([]Type, nargs) for i := range types { types[i] = x.typ() @@ -645,7 +645,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) ( arg := argList[0] check.exprOrType(x, arg, false) check.exclude(x, 1< 0 && isParameterized(sig.TypeParams().list(), x.typ()) { + if x.mode() == value && sig.TypeParams().Len() > 0 && isParameterized(sig.TypeParams().list(), x.typ()) { x.mode_ = invalid } @@ -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< hasType := false - switch x.mode_ { + switch x.mode() { case invalid, novalue, builtin, typexpr: // no type default: @@ -173,10 +177,10 @@ func operandString(x *operand, qf Qualifier) string { } // - buf.WriteString(operandModeString[x.mode_]) + buf.WriteString(operandModeString[x.mode()]) // - if x.mode_ == constant_ { + if x.mode() == constant_ { if s := x.val.String(); s != expr { buf.WriteByte(' ') buf.WriteString(s) @@ -301,9 +305,9 @@ func (x *operand) setConst(k syntax.LitKind, lit string) { // isNil reports whether x is the (untyped) nil value. func (x *operand) isNil() bool { if isTypes2 { - return x.mode_ == nilvalue + return x.mode() == nilvalue } else { // go/types - return x.mode_ == value && x.typ() == Typ[UntypedNil] + return x.mode() == value && x.typ() == Typ[UntypedNil] } } @@ -314,7 +318,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.mode() == invalid || !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 c6f7be3319..1135066af8 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.mode() != invalid && 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.mode() != invalid { 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.mode() != invalid && !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/recording.go b/src/cmd/compile/internal/types2/recording.go index c6eaed9077..8144bb55ee 100644 --- a/src/cmd/compile/internal/types2/recording.go +++ b/src/cmd/compile/internal/types2/recording.go @@ -17,7 +17,7 @@ func (check *Checker) record(x *operand) { // TODO(gri) this code can be simplified var typ Type var val constant.Value - switch x.mode_ { + switch x.mode() { case invalid: typ = Typ[Invalid] case novalue: @@ -33,9 +33,9 @@ func (check *Checker) record(x *operand) { if isUntyped(typ) { // delay type and value recording until we know the type // or until the end of type checking - check.rememberUntyped(x.expr, false, x.mode_, typ.(*Basic), val) + check.rememberUntyped(x.expr, false, x.mode(), typ.(*Basic), val) } else { - check.recordTypeAndValue(x.expr, x.mode_, typ, val) + check.recordTypeAndValue(x.expr, x.mode(), typ, val) } } @@ -94,7 +94,7 @@ func (check *Checker) recordBuiltinType(f syntax.Expr, sig *Signature) { func (check *Checker) recordCommaOkTypes(x syntax.Expr, a []*operand) { assert(x != nil) assert(len(a) == 2) - if a[0].mode_ == invalid { + if a[0].mode() == invalid { return } t0, t1 := a[0].typ(), a[1].typ() diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index 1c18a6278b..ecc202ddad 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -238,20 +238,20 @@ L: for _, e := range values { var v operand check.expr(nil, &v, e) - if x.mode_ == invalid || v.mode_ == invalid { + if x.mode() == invalid || v.mode() == invalid { continue L } check.convertUntyped(&v, x.typ()) - if v.mode_ == invalid { + if v.mode() == invalid { 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.mode() == invalid { continue L } - if v.mode_ != constant_ { + if v.mode() != constant_ { continue L // we're done } // look for duplicate values @@ -444,7 +444,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) { kind := check.rawExpr(nil, &x, s.X, nil, false) var msg string var code Code - switch x.mode_ { + switch x.mode() { default: if kind == statement { return @@ -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.mode() == invalid || val.mode() == invalid { 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.mode() == invalid { 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.mode() != invalid && !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.mode() != invalid && !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.mode() != invalid && !Comparable(x.typ()) && !hasNil(x.typ()) { check.errorf(&x, InvalidExprSwitch, "cannot switch on %s (%s is not comparable)", &x, x.typ()) x.mode_ = invalid } @@ -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.mode() != invalid { 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 69d1d76174..a9575230cf 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -248,7 +248,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *TypeName) (T Type) { var x operand check.ident(&x, e, true) - switch x.mode_ { + switch x.mode() { case typexpr: return x.typ() case invalid: @@ -263,7 +263,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *TypeName) (T Type) { var x operand check.selector(&x, e, true) - switch x.mode_ { + switch x.mode() { case typexpr: return x.typ() case invalid: @@ -482,8 +482,8 @@ 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.mode() != constant_ { + if x.mode() != invalid { 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 2b9c2d5065..36413ff312 100644 --- a/src/go/types/assignments.go +++ b/src/go/types/assignments.go @@ -24,7 +24,7 @@ import ( func (check *Checker) assignment(x *operand, T Type, context string) { check.singleValue(x) - switch x.mode_ { + switch x.mode() { case invalid: return // error reported before case nilvalue: @@ -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.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) { if lhs.typ == nil { lhs.typ = Typ[Invalid] } @@ -127,7 +127,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) { } // rhs must be a constant - if x.mode_ != constant_ { + if x.mode() != constant_ { check.errorf(x, InvalidConstInit, "%s is not constant", x) 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.mode() == invalid { 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.mode() == invalid || !isValid(x.typ()) || !isValid(lhs.typ) { if lhs.typ == nil { lhs.typ = Typ[Invalid] } @@ -219,13 +219,13 @@ 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.mode() == invalid || !isValid(x.typ()) { return Typ[Invalid] } // spec: "Each left-hand side operand must be addressable, a map index // expression, or the blank identifier. Operands may be parenthesized." - switch x.mode_ { + switch x.mode() { case invalid: return Typ[Invalid] case variable, mapindex: @@ -234,7 +234,7 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type { if sel, ok := x.expr.(*ast.SelectorExpr); ok { var op operand check.expr(nil, &op, sel.X) - if op.mode_ == mapindex { + if op.mode() == mapindex { check.errorf(&x, UnaddressableFieldAssign, "cannot assign to struct field %s in map", ExprString(x.expr)) return Typ[Invalid] } @@ -444,7 +444,7 @@ func (check *Checker) initVars(lhs []*Var, orig_rhs []ast.Expr, returnStmt ast.S } // Only record comma-ok expression if both initializations succeeded // (go.dev/issue/59371). - if commaOk && rhs[0].mode_ != invalid && rhs[1].mode_ != invalid { + if commaOk && rhs[0].mode() != invalid && rhs[1].mode() != invalid { check.recordCommaOkTypes(orig_rhs[0], rhs) } return @@ -452,7 +452,7 @@ func (check *Checker) initVars(lhs []*Var, orig_rhs []ast.Expr, returnStmt ast.S // In all other cases we have an assignment mismatch. // Only report a mismatch error if there are no other errors on the rhs. - if rhs[0].mode_ != invalid { + if rhs[0].mode() != invalid { if returnStmt != nil { check.returnError(returnStmt, lhs, rhs) } else { @@ -508,7 +508,7 @@ func (check *Checker) assignVars(lhs, orig_rhs []ast.Expr) { } // Only record comma-ok expression if both assignments succeeded // (go.dev/issue/59371). - if commaOk && rhs[0].mode_ != invalid && rhs[1].mode_ != invalid { + if commaOk && rhs[0].mode() != invalid && rhs[1].mode() != invalid { check.recordCommaOkTypes(orig_rhs[0], rhs) } return @@ -516,7 +516,7 @@ func (check *Checker) assignVars(lhs, orig_rhs []ast.Expr) { // In all other cases we have an assignment mismatch. // Only report a mismatch error if there are no other errors on the rhs. - if rhs[0].mode_ != invalid { + if rhs[0].mode() != invalid { check.assignError(orig_rhs, l, r) } check.useLHS(lhs...) diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index 146e8d6574..1f55368826 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.mode() == invalid { return } } @@ -154,7 +154,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b switch t := arrayPtrDeref(x.typ().Underlying()).(type) { case *Basic: if isString(t) && id == _Len { - if x.mode_ == constant_ { + if x.mode() == constant_ { mode = constant_ val = constant.MakeInt64(int64(len(constant.StringVal(x.val)))) } else { @@ -300,7 +300,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b // both of them to float64 since they must have the // same type to succeed (this will result in an error // because shifts of floats are not permitted) - if x.mode_ == constant_ && y.mode_ == constant_ { + if x.mode() == constant_ && y.mode() == constant_ { toFloat := func(x *operand) { if isNumeric(x.typ()) && constant.Sign(constant.Imag(x.val)) == 0 { x.typ_ = Typ[UntypedFloat] @@ -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.mode() == invalid || y.mode() == invalid { return } @@ -348,13 +348,13 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b } // if both arguments are constants, the result is a constant - if x.mode_ == constant_ && y.mode_ == constant_ { + if x.mode() == constant_ && y.mode() == constant_ { x.val = constant.BinaryOp(constant.ToFloat(x.val), token.ADD, constant.MakeImag(constant.ToFloat(y.val))) } else { x.mode_ = value } - if check.recordTypes() && x.mode_ != constant_ { + if check.recordTypes() && x.mode() != constant_ { check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ(), x.typ())) } @@ -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.mode() == invalid { return } @@ -456,7 +456,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b // convert or check untyped argument if isUntyped(x.typ()) { - if x.mode_ == constant_ { + if x.mode() == constant_ { // an untyped constant number can always be considered // as a complex constant if isNumeric(x.typ()) { @@ -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.mode() == invalid { return } } @@ -502,7 +502,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b } // if the argument is a constant, the result is a constant - if x.mode_ == constant_ { + if x.mode() == constant_ { if id == _Real { x.val = constant.Real(x.val) } else { @@ -512,7 +512,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b x.mode_ = value } - if check.recordTypes() && x.mode_ != constant_ { + if check.recordTypes() && x.mode() != constant_ { check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ())) } @@ -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.mode() == invalid { 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.mode() == invalid { return } @@ -609,7 +609,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b return } - if x.mode_ == constant_ && a.mode_ == constant_ { + if x.mode() == constant_ && a.mode() == constant_ { if constant.Compare(a.val, op, x.val) { *x = *a } @@ -620,11 +620,11 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b } // If nargs == 1, make sure x.mode is either a value or a constant. - if x.mode_ != constant_ { + if x.mode() != constant_ { 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.mode() == invalid { return } } @@ -634,7 +634,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b check.updateExprType(a.expr, x.typ(), true) } - if check.recordTypes() && x.mode_ != constant_ { + if check.recordTypes() && x.mode() != constant_ { types := make([]Type, nargs) for i := range types { types[i] = x.typ() @@ -648,7 +648,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b arg := argList[0] check.exprOrType(x, arg, false) check.exclude(x, 1< 0 && isParameterized(sig.TypeParams().list(), x.typ()) { + if x.mode() == value && sig.TypeParams().Len() > 0 && isParameterized(sig.TypeParams().list(), x.typ()) { x.mode_ = invalid } @@ -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< hasType := false - switch x.mode_ { + switch x.mode() { case invalid, novalue, builtin, typexpr: // no type default: @@ -177,10 +181,10 @@ func operandString(x *operand, qf Qualifier) string { } // - buf.WriteString(operandModeString[x.mode_]) + buf.WriteString(operandModeString[x.mode()]) // - if x.mode_ == constant_ { + if x.mode() == constant_ { if s := x.val.String(); s != expr { buf.WriteByte(' ') buf.WriteString(s) @@ -305,9 +309,9 @@ func (x *operand) setConst(k token.Token, lit string) { // isNil reports whether x is the (untyped) nil value. func (x *operand) isNil() bool { if isTypes2 { - return x.mode_ == nilvalue + return x.mode() == nilvalue } else { // go/types - return x.mode_ == value && x.typ() == Typ[UntypedNil] + return x.mode() == value && x.typ() == Typ[UntypedNil] } } @@ -318,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.mode() == invalid || !isValid(T) { return true, 0 // avoid spurious errors } diff --git a/src/go/types/range.go b/src/go/types/range.go index cbe2c37535..05ef827eec 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.mode() != invalid && 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.mode() != invalid { 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.mode() != invalid && !isInteger(x.typ()) { check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ()) } } else { diff --git a/src/go/types/recording.go b/src/go/types/recording.go index d440259c28..809246bb05 100644 --- a/src/go/types/recording.go +++ b/src/go/types/recording.go @@ -20,7 +20,7 @@ func (check *Checker) record(x *operand) { // TODO(gri) this code can be simplified var typ Type var val constant.Value - switch x.mode_ { + switch x.mode() { case invalid: typ = Typ[Invalid] case novalue: @@ -36,9 +36,9 @@ func (check *Checker) record(x *operand) { if isUntyped(typ) { // delay type and value recording until we know the type // or until the end of type checking - check.rememberUntyped(x.expr, false, x.mode_, typ.(*Basic), val) + check.rememberUntyped(x.expr, false, x.mode(), typ.(*Basic), val) } else { - check.recordTypeAndValue(x.expr, x.mode_, typ, val) + check.recordTypeAndValue(x.expr, x.mode(), typ, val) } } @@ -97,7 +97,7 @@ func (check *Checker) recordBuiltinType(f ast.Expr, sig *Signature) { func (check *Checker) recordCommaOkTypes(x ast.Expr, a []*operand) { assert(x != nil) assert(len(a) == 2) - if a[0].mode_ == invalid { + if a[0].mode() == invalid { return } t0, t1 := a[0].typ(), a[1].typ() diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index a449feb220..ee2f872577 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -239,20 +239,20 @@ L: for _, e := range values { var v operand check.expr(nil, &v, e) - if x.mode_ == invalid || v.mode_ == invalid { + if x.mode() == invalid || v.mode() == invalid { continue L } check.convertUntyped(&v, x.typ()) - if v.mode_ == invalid { + if v.mode() == invalid { 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.mode() == invalid { continue L } - if v.mode_ != constant_ { + if v.mode() != constant_ { continue L // we're done } // look for duplicate values @@ -445,7 +445,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) { kind := check.rawExpr(nil, &x, s.X, nil, false) var msg string var code Code - switch x.mode_ { + switch x.mode() { default: if kind == statement { return @@ -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.mode() == invalid || val.mode() == invalid { 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.mode() == invalid { 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.mode() == invalid { 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.mode() == invalid { 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.mode() != invalid && !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.mode() != invalid && !Comparable(x.typ()) && !hasNil(x.typ()) { check.errorf(&x, InvalidExprSwitch, "cannot switch on %s (%s is not comparable)", &x, x.typ()) x.mode_ = invalid } @@ -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.mode() != invalid { 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.mode() != invalid && !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 848d662f10..79b7f6b5ca 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -246,7 +246,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *TypeName) (T Type) { var x operand check.ident(&x, e, true) - switch x.mode_ { + switch x.mode() { case typexpr: return x.typ() case invalid: @@ -261,7 +261,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *TypeName) (T Type) { var x operand check.selector(&x, e, true) - switch x.mode_ { + switch x.mode() { case typexpr: return x.typ() case invalid: @@ -478,8 +478,8 @@ 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.mode() != constant_ { + if x.mode() != invalid { check.errorf(&x, InvalidArrayLen, "array length %s must be constant", &x) } return -1 -- 2.52.0