]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: mechanically replace read accesses to operand.mode_
authorMark Freeman <mark@golang.org>
Wed, 4 Feb 2026 21:46:40 +0000 (16:46 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 5 Feb 2026 22:24:18 +0000 (14:24 -0800)
Change-Id: Ib832f4f9fde45b1308208f05756960191953e8f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/742081
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index 1e00dade6a958b88acc3dda84e02dd9789fc0a86..5903a5a310940ca45441c2c54f54d2d93e29ae71 100644 (file)
@@ -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...)
index f64758a92b19483039a4d0d2dde2139cb62cc1dd..c975767fc66f4d0c6cfb29e9c681f5042c0caa5d 100644 (file)
@@ -53,7 +53,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                args = check.exprList(argList)
                nargs = len(args)
                for _, a := range args {
-                       if a.mode_ == invalid {
+                       if a.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<<novalue|1<<builtin)
-               switch x.mode_ {
+               switch x.mode() {
                case invalid:
                        return
                case typexpr:
@@ -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.mode() == invalid {
                                        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.mode() == invalid {
                        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.mode() == invalid {
                                        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.mode() == invalid {
                        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.mode() == invalid {
                        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.mode() == invalid {
                        return
                }
 
@@ -806,7 +806,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // record the selector expression (was bug - go.dev/issue/47895)
                {
                        mode := value
-                       if x.mode_ == variable || indirect {
+                       if x.mode() == variable || indirect {
                                mode = variable
                        }
                        check.record(&operand{mode, selx, obj.Type(), nil, 0})
@@ -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.mode() == invalid {
                        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.mode() == invalid {
                        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.mode() == invalid {
                        return
                }
 
@@ -935,7 +935,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // assert(pred) causes a typechecker error if pred is false.
                // The result of assert is the value of pred if there is no error.
                // Note: assert is only available in self-test mode.
-               if x.mode_ != constant_ || !isBoolean(x.typ()) {
+               if x.mode() != constant_ || !isBoolean(x.typ()) {
                        check.errorf(x, Test, invalidArg+"%s is not a boolean constant", x)
                        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.mode() == invalid {
                        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.mode() != invalid)
        return true
 }
 
index 0de514f4f42c2787c04375a63884f175648be68a..0e73c25f25d6afe052a5884db683ae02ae54bc25 100644 (file)
@@ -175,7 +175,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                        // Delay function instantiation to argument checking,
                        // where we combine type and value arguments for type
                        // inference.
-                       assert(x.mode_ == value)
+                       assert(x.mode() == value)
                        inst = iexpr
                }
                x.expr = iexpr
@@ -185,7 +185,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
        }
        // x.typ may be generic
 
-       switch x.mode_ {
+       switch x.mode() {
        case invalid:
                check.use(call.ArgList...)
                x.expr = call
@@ -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.mode() == invalid {
                        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.mode() != invalid {
                                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.mode() != invalid && x.mode() != constant_ {
                        check.hasCallOrRecv = true
                }
                return predeclaredFuncs[id].kind
@@ -245,7 +245,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
 
        // ordinary function/method call
        // signature may be generic
-       cgocall := x.mode_ == cgofunc
+       cgocall := x.mode() == cgofunc
 
        // If the operand type is a type parameter, all types in its type set
        // must have a common underlying type, which must be a signature.
@@ -341,7 +341,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
 
        // if type inference failed, a parameterized result must be invalidated
        // (operands cannot have a parameterized type)
-       if x.mode_ == value && sig.TypeParams().Len() > 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<<novalue|1<<builtin|1<<typexpr)
-                       if t, ok := x.typ().(*Tuple); ok && x.mode_ != invalid {
+                       if t, ok := x.typ().(*Tuple); ok && x.mode() != invalid {
                                // x is a function call returning multiple values; it cannot be generic.
                                resList = make([]*operand, t.Len())
                                for i, v := range t.vars {
@@ -788,7 +788,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
        }
 
        check.exprOrType(x, e.X, false)
-       switch x.mode_ {
+       switch x.mode() {
        case builtin:
                check.errorf(e.Pos(), UncalledBuiltin, "invalid use of %s in selector expression", x)
                goto Error
@@ -822,7 +822,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
                goto Error
        }
 
-       obj, index, indirect = lookupFieldOrMethod(x.typ(), x.mode_ == variable, check.pkg, sel, false)
+       obj, index, indirect = lookupFieldOrMethod(x.typ(), x.mode() == variable, check.pkg, sel, false)
        if obj == nil {
                // Don't report another error if the underlying type was invalid (go.dev/issue/49541).
                if !isValid(x.typ().Underlying()) {
@@ -836,7 +836,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
                }
 
                if indirect {
-                       if x.mode_ == typexpr {
+                       if x.mode() == typexpr {
                                check.errorf(e.Sel, InvalidMethodExpr, "invalid method expression %s.%s (needs pointer receiver (*%s).%s)", x.typ(), sel, x.typ(), sel)
                        } else {
                                check.errorf(e.Sel, InvalidMethodExpr, "cannot call pointer method %s on %s", sel, x.typ())
@@ -848,7 +848,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
                if isInterfacePtr(x.typ()) {
                        why = check.interfacePtrError(x.typ())
                } else {
-                       alt, _, _ := lookupFieldOrMethod(x.typ(), x.mode_ == variable, check.pkg, sel, true)
+                       alt, _, _ := lookupFieldOrMethod(x.typ(), x.mode() == variable, check.pkg, sel, true)
                        why = check.lookupError(x.typ(), sel, alt, false)
                }
                check.errorf(e.Sel, MissingFieldOrMethod, "%s.%s undefined (%s)", x.expr, sel, why)
@@ -858,14 +858,14 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
 
        switch obj := obj.(type) {
        case *Var:
-               if x.mode_ == typexpr {
+               if x.mode() == typexpr {
                        check.errorf(e.X, MissingFieldOrMethod, "operand for field selector %s must be value of type %s", sel, x.typ())
                        goto Error
                }
 
                // field value
                check.recordSelection(e, FieldVal, x.typ(), obj, index, indirect)
-               if x.mode_ == variable || indirect {
+               if x.mode() == variable || indirect {
                        x.mode_ = variable
                } else {
                        x.mode_ = value
@@ -876,7 +876,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
                check.objDecl(obj) // ensure fully set-up signature
                check.addDeclDep(obj)
 
-               if x.mode_ == typexpr {
+               if x.mode() == typexpr {
                        // method expression
                        check.recordSelection(e, MethodExpr, x.typ(), obj, index, indirect)
 
@@ -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.mode() != invalid
 }
index 271c659c0c7382dfcf4b1fd5223b252c24714d39..875386d6ba56a1dde58206d8de1ffe4ed02d9879 100644 (file)
@@ -18,7 +18,7 @@ import (
 // For untyped constants, it checks that the value doesn't become
 // arbitrarily large.
 func (check *Checker) overflow(x *operand, opPos syntax.Pos) {
-       assert(x.mode_ == constant_)
+       assert(x.mode() == constant_)
 
        if x.val.Kind() == constant.Unknown {
                // TODO(gri) We should report exactly what went wrong. At the
@@ -250,7 +250,7 @@ func (check *Checker) representable(x *operand, typ *Basic) {
 //
 // If no such representation is possible, it returns a non-zero error code.
 func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, Code) {
-       assert(x.mode_ == constant_)
+       assert(x.mode() == constant_)
        v := x.val
        if !representableConst(x.val, check, typ, &v) {
                if isNumeric(x.typ()) && isNumeric(typ) {
index 329878be5ab9d96bec246c13c935b41b663ba410..40f982c332ef3ec28d277b7a1b9bf1a99d0a3e4a 100644 (file)
@@ -15,7 +15,7 @@ import (
 // conversion type-checks the conversion T(x).
 // The result is in x.
 func (check *Checker) conversion(x *operand, T Type) {
-       constArg := x.mode_ == constant_
+       constArg := x.mode() == constant_
 
        constConvertibleTo := func(T Type, val *constant.Value) bool {
                switch t, _ := T.Underlying().(*Basic); {
@@ -110,7 +110,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                        // ok
                } else if isNonTypeParamInterface(T) || constArg && !isConstType(T) || !isTypes2 && x.isNil() {
                        final = Default(x.typ()) // default type of untyped nil is untyped nil
-               } else if x.mode_ == constant_ && isInteger(x.typ()) && allString(T) {
+               } else if x.mode() == constant_ && isInteger(x.typ()) && allString(T) {
                        final = x.typ()
                }
                check.updateExprType(x.expr, final, true)
index d35d108b5ae5a8c6a645f8553f758514f1f277c9..7925dbfb05dffd09f45379b81c0918a64776b99c 100644 (file)
@@ -129,7 +129,7 @@ var op2str2 = [...]string{
 
 func (check *Checker) unary(x *operand, e *syntax.Operation) {
        check.expr(nil, x, e.X)
-       if x.mode_ == invalid {
+       if x.mode() == invalid {
                return
        }
 
@@ -138,7 +138,7 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
        case syntax.And:
                // spec: "As an exception to the addressability
                // requirement x may also be a composite literal."
-               if _, ok := syntax.Unparen(e.X).(*syntax.CompositeLit); !ok && x.mode_ != variable {
+               if _, ok := syntax.Unparen(e.X).(*syntax.CompositeLit); !ok && x.mode() != variable {
                        check.errorf(x, UnaddressableOperand, invalidOp+"cannot take address of %s", x)
                        x.mode_ = invalid
                        return
@@ -174,7 +174,7 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
                return
        }
 
-       if x.mode_ == constant_ {
+       if x.mode() == constant_ {
                if x.val.Kind() == constant.Unknown {
                        // nothing to do (and don't cause an error below in the overflow check)
                        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.mode() == invalid {
                        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.mode() == invalid || isTyped(x.typ()) || !isValid(target) {
                return x.typ(), nil, 0
        }
        // x is untyped
@@ -434,7 +434,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
 
        switch u := target.Underlying().(type) {
        case *Basic:
-               if x.mode_ == constant_ {
+               if x.mode() == constant_ {
                        v, code := check.representation(x, u)
                        if code != 0 {
                                return nil, nil, code
@@ -569,7 +569,7 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase b
        }
 
        // comparison is ok
-       if x.mode_ == constant_ && y.mode_ == constant_ {
+       if x.mode() == constant_ && y.mode() == constant_ {
                x.val = constant.MakeBool(constant.Compare(x.val, op2tok[op], y.val))
                // The operands are never materialized; no need to update
                // their types.
@@ -630,7 +630,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
        // TODO(gri) This function seems overly complex. Revisit.
 
        var xval constant.Value
-       if x.mode_ == constant_ {
+       if x.mode() == constant_ {
                xval = constant.ToInt(x.val)
        }
 
@@ -650,7 +650,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
        // Check that constants are representable by uint, but do not convert them
        // (see also go.dev/issue/47243).
        var yval constant.Value
-       if y.mode_ == constant_ {
+       if y.mode() == constant_ {
                // Provide a good error message for negative shift counts.
                yval = constant.ToInt(y.val) // consider -1, 1.0, but not -1.1
                if yval.Kind() == constant.Int && constant.Sign(yval) < 0 {
@@ -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.mode() == invalid {
                                x.mode_ = invalid
                                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.mode() == invalid {
                                x.mode_ = invalid
                                return
                        }
@@ -691,8 +691,8 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                }
        }
 
-       if x.mode_ == constant_ {
-               if y.mode_ == constant_ {
+       if x.mode() == constant_ {
+               if y.mode() == constant_ {
                        // if either x or y has an unknown value, the result is unknown
                        if x.val.Kind() == constant.Unknown || y.val.Kind() == constant.Unknown {
                                x.val = constant.MakeUnknown()
@@ -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.mode() == invalid {
                return
        }
-       if y.mode_ == invalid {
+       if y.mode() == invalid {
                x.mode_ = invalid
                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.mode() == invalid {
                return
        }
 
@@ -839,14 +839,14 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
 
        if op == syntax.Div || op == syntax.Rem {
                // check for zero divisor
-               if (x.mode_ == constant_ || allInteger(x.typ())) && y.mode_ == constant_ && constant.Sign(y.val) == 0 {
+               if (x.mode() == constant_ || allInteger(x.typ())) && y.mode() == constant_ && constant.Sign(y.val) == 0 {
                        check.error(&y, DivByZero, invalidOp+"division by zero")
                        x.mode_ = invalid
                        return
                }
 
                // check for divisor underflow in complex division (see go.dev/issue/20227)
-               if x.mode_ == constant_ && y.mode_ == constant_ && isComplex(x.typ()) {
+               if x.mode() == constant_ && y.mode() == constant_ && isComplex(x.typ()) {
                        re, im := constant.Real(y.val), constant.Imag(y.val)
                        re2, im2 := constant.BinaryOp(re, token.MUL, re), constant.BinaryOp(im, token.MUL, im)
                        if constant.Sign(re2) == 0 && constant.Sign(im2) == 0 {
@@ -857,7 +857,7 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
                }
        }
 
-       if x.mode_ == constant_ && y.mode_ == constant_ {
+       if x.mode() == constant_ && y.mode() == constant_ {
                // if either x or y has an unknown value, the result is unknown
                if x.val.Kind() == constant.Unknown || y.val.Kind() == constant.Unknown {
                        x.val = constant.MakeUnknown()
@@ -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.mode() == invalid {
                        return
                }
                check.convertUntyped(y, x.typ())
-               if y.mode_ == invalid {
+               if y.mode() == invalid {
                        x.mode_ = invalid
                        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.mode() == invalid || 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.mode() == invalid {
                        goto Error
                }
 
        case *syntax.FuncLit:
                check.funcLit(x, e)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        goto Error
                }
 
        case *syntax.CompositeLit:
                check.compositeLit(x, e, hint)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        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.mode() == invalid {
                        goto Error
                }
 
        case *syntax.SliceExpr:
                check.sliceExpr(x, e)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        goto Error
                }
 
        case *syntax.AssertExpr:
                check.expr(nil, x, e.X)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        goto Error
                }
                // x.(type) expressions are encoded via TypeSwitchGuards
@@ -1169,7 +1169,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                        if e.Op == syntax.Mul {
                                // pointer indirection
                                check.exprOrType(x, e.X, false)
-                               switch x.mode_ {
+                               switch x.mode() {
                                case invalid:
                                        goto Error
                                case typexpr:
@@ -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.mode() == invalid {
                                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.mode() == invalid {
                        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.mode() != invalid {
                // multiple values
                list = make([]*operand, t.Len())
                for i, v := range t.vars {
@@ -1344,9 +1344,9 @@ func (check *Checker) multiExpr(e syntax.Expr, allowCommaOk bool) (list []*opera
 
        // exactly one (possibly invalid or comma-ok) value
        list = []*operand{&x}
-       if allowCommaOk && (x.mode_ == mapindex || x.mode_ == commaok || x.mode_ == commaerr) {
+       if allowCommaOk && (x.mode() == mapindex || x.mode() == commaok || x.mode() == commaerr) {
                x2 := &operand{mode_: value, expr: e, typ_: Typ[UntypedBool]}
-               if x.mode_ == commaerr {
+               if x.mode() == commaerr {
                        x2.typ_ = universeError
                }
                list = append(list, x2)
@@ -1379,10 +1379,10 @@ func (check *Checker) exprOrType(x *operand, e syntax.Expr, allowGeneric bool) {
 // exclude reports an error if x.mode is in modeset and sets x.mode to invalid.
 // The modeset may contain any of 1<<novalue, 1<<builtin, 1<<typexpr.
 func (check *Checker) exclude(x *operand, modeset uint) {
-       if modeset&(1<<x.mode_) != 0 {
+       if modeset&(1<<x.mode()) != 0 {
                var msg string
                var code Code
-               switch x.mode_ {
+               switch x.mode() {
                case novalue:
                        if modeset&(1<<typexpr) != 0 {
                                msg = "%s used as value"
@@ -1406,7 +1406,7 @@ func (check *Checker) exclude(x *operand, modeset uint) {
 
 // singleValue reports an error if x describes a tuple and sets x.mode to invalid.
 func (check *Checker) singleValue(x *operand) {
-       if x.mode_ == value {
+       if x.mode() == value {
                // tuple types are never named - no need for underlying type below
                if t, ok := x.typ().(*Tuple); ok {
                        assert(t.Len() != 1)
index 12d89e9cae21c77ac647d5bfe87c95c0af4baa9e..68a7e620758d52039ca4ce930d3f7dee444a5983 100644 (file)
@@ -19,7 +19,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
        check.exprOrType(x, e.X, true)
        // x may be generic
 
-       switch x.mode_ {
+       switch x.mode() {
        case invalid:
                check.use(e.Index)
                return false
@@ -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.mode() == invalid {
                return false
        }
 
@@ -76,7 +76,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
        case *Basic:
                if isString(typ) {
                        valid = true
-                       if x.mode_ == constant_ {
+                       if x.mode() == constant_ {
                                length = int64(len(constant.StringVal(x.val)))
                        }
                        // an indexed string always yields a byte value
@@ -89,7 +89,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
        case *Array:
                valid = true
                length = typ.len
-               if x.mode_ != variable {
+               if x.mode() != variable {
                        x.mode_ = value
                }
                x.typ_ = typ.elem
@@ -142,7 +142,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                        case *Array:
                                l = t.len
                                e = t.elem
-                               if x.mode_ != variable {
+                               if x.mode() != variable {
                                        mode = value
                                }
                        case *Pointer:
@@ -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.mode() == invalid {
                check.use(e.Index[:]...)
                return
        }
@@ -301,7 +301,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
                                return
                        }
                        valid = true
-                       if x.mode_ == constant_ {
+                       if x.mode() == constant_ {
                                length = int64(len(constant.StringVal(x.val)))
                        }
                        // spec: "For untyped string operands the result
@@ -314,7 +314,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
        case *Array:
                valid = true
                length = u.len
-               if x.mode_ != variable {
+               if x.mode() != variable {
                        check.errorf(x, NonSliceableOperand, "cannot slice unaddressable value %s", x)
                        x.mode_ = invalid
                        return
@@ -427,7 +427,7 @@ func (check *Checker) index(index syntax.Expr, max int64) (typ Type, val int64)
                return
        }
 
-       if x.mode_ != constant_ {
+       if x.mode() != constant_ {
                return x.typ(), -1
        }
 
@@ -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.mode() == invalid {
                return false
        }
 
        // spec: "a constant index that is untyped is given type int"
        check.convertUntyped(x, Typ[Int])
-       if x.mode_ == invalid {
+       if x.mode() == invalid {
                return false
        }
 
@@ -467,7 +467,7 @@ func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNega
                return false
        }
 
-       if x.mode_ == constant_ {
+       if x.mode() == constant_ {
                // spec: "a constant index must be non-negative ..."
                if !allowNegative && constant.Sign(x.val) < 0 {
                        check.errorf(x, code, invalidArg+"%s %s must not be negative", what, x)
index 0cd6aaf999e0b0b9a9268a85510f9e12def59c13..3aeace192e41b3c84066f760811a78391a926ca8 100644 (file)
@@ -62,7 +62,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        // If we have invalid (ordinary) arguments, an error was reported before.
        // Avoid additional inference errors and exit early (go.dev/issue/60434).
        for _, arg := range args {
-               if arg.mode_ == invalid {
+               if arg.mode() == invalid {
                        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.mode() == invalid {
                        // An error was reported earlier. Ignore this arg
                        // and continue, we may still be able to infer all
                        // targs resulting in fewer follow-on errors.
index 5459d7f5c1d80caea1cb94740a05c45a9db23d0e..c52e070e44d93e4b6d0ed9c4eeb8f887bac9487b 100644 (file)
@@ -62,7 +62,7 @@ func (check *Checker) basicLit(x *operand, e *syntax.BasicLit) {
                }
        }
        x.setConst(e.Kind, e.Value)
-       if x.mode_ == invalid {
+       if x.mode() == invalid {
                // 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,10 +261,10 @@ 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.mode() == invalid {
                                continue
                        }
-                       if x.mode_ == constant_ {
+                       if x.mode() == constant_ {
                                duplicate := false
                                xkey := keyVal(x.val)
                                if keyIsInterface {
index 1d29810a724aa973c55bcebf97219ff7d9ad5bcc..fe06fc78613c2cadcc3bb875fd2143fc5d727111 100644 (file)
@@ -60,12 +60,16 @@ type operand struct {
        id    builtinId
 }
 
+func (x *operand) mode() operandMode {
+       return x.mode_
+}
+
 func (x *operand) typ() Type {
        return x.typ_
 }
 
 func (x *operand) isValid() bool {
-       return x.mode_ != invalid
+       return x.mode() != invalid
 }
 
 // Pos returns the position of the expression corresponding to x.
@@ -117,7 +121,7 @@ func (x *operand) Pos() syntax.Pos {
 func operandString(x *operand, qf Qualifier) string {
        // special-case nil
        if isTypes2 {
-               if x.mode_ == nilvalue {
+               if x.mode() == nilvalue {
                        switch x.typ() {
                        case nil, Typ[Invalid]:
                                return "nil (with invalid type)"
@@ -128,7 +132,7 @@ func operandString(x *operand, qf Qualifier) string {
                        }
                }
        } else { // go/types
-               if x.mode_ == value && x.typ() == Typ[UntypedNil] {
+               if x.mode() == value && x.typ() == Typ[UntypedNil] {
                        return "nil"
                }
        }
@@ -139,7 +143,7 @@ func operandString(x *operand, qf Qualifier) string {
        if x.expr != nil {
                expr = ExprString(x.expr)
        } else {
-               switch x.mode_ {
+               switch x.mode() {
                case builtin:
                        expr = predeclaredFuncs[x.id].name
                case typexpr:
@@ -157,7 +161,7 @@ func operandString(x *operand, qf Qualifier) string {
 
        // <untyped kind>
        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 {
        }
 
        // <mode>
-       buf.WriteString(operandModeString[x.mode_])
+       buf.WriteString(operandModeString[x.mode()])
 
        // <val>
-       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
        }
 
index c6f7be331904a90952d526895b59a299a8d21e09..1135066af8626397bd5bc4f9f0084d2cf0b55e91 100644 (file)
@@ -34,7 +34,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
        check.hasCallOrRecv = false
        check.expr(nil, &x, rangeVar)
 
-       if isTypes2 && x.mode_ != invalid && sValue == nil && !check.hasCallOrRecv {
+       if isTypes2 && x.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 {
index c6eaed9077f0e179b248090a4db4f420fc5992bf..8144bb55ee18b080c2055b01b5cd4879dfd87385 100644 (file)
@@ -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()
index 1c18a6278bac89887631cb19c35affcc038aeb15..ecc202ddade1ac8a6790c19f43ee095a7afcc1d3 100644 (file)
@@ -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()) {
index 69d1d761740a7ee2a508c99351f9174cda43cf2e..a9575230cffc592db69d7477a3126bfa44707e78 100644 (file)
@@ -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
index 2b9c2d50655ed3ca60572de7cef5ae43699e20b4..36413ff3125a1b21e31f30d82ab75862ea7cb8af 100644 (file)
@@ -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...)
index 146e8d657400aed84ce7b3327f829c29a229773d..1f5536882693d7be91a943abf732bb690f7288d2 100644 (file)
@@ -56,7 +56,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                args = check.exprList(argList)
                nargs = len(args)
                for _, a := range args {
-                       if a.mode_ == invalid {
+                       if a.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<<novalue|1<<builtin)
-               switch x.mode_ {
+               switch x.mode() {
                case invalid:
                        return
                case typexpr:
@@ -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.mode() == invalid {
                                        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.mode() == invalid {
                        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.mode() == invalid {
                                        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.mode() == invalid {
                        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.mode() == invalid {
                        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.mode() == invalid {
                        return
                }
 
@@ -809,7 +809,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // record the selector expression (was bug - go.dev/issue/47895)
                {
                        mode := value
-                       if x.mode_ == variable || indirect {
+                       if x.mode() == variable || indirect {
                                mode = variable
                        }
                        check.record(&operand{mode, selx, obj.Type(), nil, 0})
@@ -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.mode() == invalid {
                        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.mode() == invalid {
                        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.mode() == invalid {
                        return
                }
 
@@ -938,7 +938,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // assert(pred) causes a typechecker error if pred is false.
                // The result of assert is the value of pred if there is no error.
                // Note: assert is only available in self-test mode.
-               if x.mode_ != constant_ || !isBoolean(x.typ()) {
+               if x.mode() != constant_ || !isBoolean(x.typ()) {
                        check.errorf(x, Test, invalidArg+"%s is not a boolean constant", x)
                        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.mode() == invalid {
                        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.mode() != invalid)
        return true
 }
 
index c19aebb1f0b1cf213e63fd3f7ae19b8d91970b28..d9368c618da59b5889a801da7c88a6ed6c75fc0e 100644 (file)
@@ -176,7 +176,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
                        // Delay function instantiation to argument checking,
                        // where we combine type and value arguments for type
                        // inference.
-                       assert(x.mode_ == value)
+                       assert(x.mode() == value)
                } else {
                        ix = nil
                }
@@ -187,7 +187,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
        }
        // x.typ may be generic
 
-       switch x.mode_ {
+       switch x.mode() {
        case invalid:
                check.use(call.Args...)
                x.expr = call
@@ -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.mode() == invalid {
                        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.mode() != invalid {
                                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.mode() != invalid && x.mode() != constant_ {
                        check.hasCallOrRecv = true
                }
                return predeclaredFuncs[id].kind
@@ -247,7 +247,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
 
        // ordinary function/method call
        // signature may be generic
-       cgocall := x.mode_ == cgofunc
+       cgocall := x.mode() == cgofunc
 
        // If the operand type is a type parameter, all types in its type set
        // must have a common underlying type, which must be a signature.
@@ -343,7 +343,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
 
        // if type inference failed, a parameterized result must be invalidated
        // (operands cannot have a parameterized type)
-       if x.mode_ == value && sig.TypeParams().Len() > 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<<novalue|1<<builtin|1<<typexpr)
-                       if t, ok := x.typ().(*Tuple); ok && x.mode_ != invalid {
+                       if t, ok := x.typ().(*Tuple); ok && x.mode() != invalid {
                                // x is a function call returning multiple values; it cannot be generic.
                                resList = make([]*operand, t.Len())
                                for i, v := range t.vars {
@@ -790,7 +790,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
        }
 
        check.exprOrType(x, e.X, false)
-       switch x.mode_ {
+       switch x.mode() {
        case builtin:
                // types2 uses the position of '.' for the error
                check.errorf(e.Sel, UncalledBuiltin, "invalid use of %s in selector expression", x)
@@ -825,7 +825,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                goto Error
        }
 
-       obj, index, indirect = lookupFieldOrMethod(x.typ(), x.mode_ == variable, check.pkg, sel, false)
+       obj, index, indirect = lookupFieldOrMethod(x.typ(), x.mode() == variable, check.pkg, sel, false)
        if obj == nil {
                // Don't report another error if the underlying type was invalid (go.dev/issue/49541).
                if !isValid(x.typ().Underlying()) {
@@ -839,7 +839,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                }
 
                if indirect {
-                       if x.mode_ == typexpr {
+                       if x.mode() == typexpr {
                                check.errorf(e.Sel, InvalidMethodExpr, "invalid method expression %s.%s (needs pointer receiver (*%s).%s)", x.typ(), sel, x.typ(), sel)
                        } else {
                                check.errorf(e.Sel, InvalidMethodExpr, "cannot call pointer method %s on %s", sel, x.typ())
@@ -851,7 +851,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                if isInterfacePtr(x.typ()) {
                        why = check.interfacePtrError(x.typ())
                } else {
-                       alt, _, _ := lookupFieldOrMethod(x.typ(), x.mode_ == variable, check.pkg, sel, true)
+                       alt, _, _ := lookupFieldOrMethod(x.typ(), x.mode() == variable, check.pkg, sel, true)
                        why = check.lookupError(x.typ(), sel, alt, false)
                }
                check.errorf(e.Sel, MissingFieldOrMethod, "%s.%s undefined (%s)", x.expr, sel, why)
@@ -861,14 +861,14 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
 
        switch obj := obj.(type) {
        case *Var:
-               if x.mode_ == typexpr {
+               if x.mode() == typexpr {
                        check.errorf(e.X, MissingFieldOrMethod, "operand for field selector %s must be value of type %s", sel, x.typ())
                        goto Error
                }
 
                // field value
                check.recordSelection(e, FieldVal, x.typ(), obj, index, indirect)
-               if x.mode_ == variable || indirect {
+               if x.mode() == variable || indirect {
                        x.mode_ = variable
                } else {
                        x.mode_ = value
@@ -879,7 +879,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                check.objDecl(obj) // ensure fully set-up signature
                check.addDeclDep(obj)
 
-               if x.mode_ == typexpr {
+               if x.mode() == typexpr {
                        // method expression
                        check.recordSelection(e, MethodExpr, x.typ(), obj, index, indirect)
 
@@ -938,7 +938,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                                // any incomplete interfaces so they are available to NewMethodSet
                                // (which assumes that interfaces have been completed already).
                                typ := x.typ_
-                               if x.mode_ == variable {
+                               if x.mode() == variable {
                                        // If typ is not an (unnamed) pointer or an interface,
                                        // use *typ instead, because the method set of *typ
                                        // includes the methods of typ.
@@ -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.mode() != invalid
 }
index 285f286a9d6512a7668057ac08210622daa256e6..5162aac22cb0280f13ad587287e7aa7c88a55b7b 100644 (file)
@@ -20,7 +20,7 @@ import (
 // For untyped constants, it checks that the value doesn't become
 // arbitrarily large.
 func (check *Checker) overflow(x *operand, opPos token.Pos) {
-       assert(x.mode_ == constant_)
+       assert(x.mode() == constant_)
 
        if x.val.Kind() == constant.Unknown {
                // TODO(gri) We should report exactly what went wrong. At the
@@ -252,7 +252,7 @@ func (check *Checker) representable(x *operand, typ *Basic) {
 //
 // If no such representation is possible, it returns a non-zero error code.
 func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, Code) {
-       assert(x.mode_ == constant_)
+       assert(x.mode() == constant_)
        v := x.val
        if !representableConst(x.val, check, typ, &v) {
                if isNumeric(x.typ()) && isNumeric(typ) {
index 905f7225457ff9a4ba369fc39019973d239599ea..7f0bc8efb2b31925eef1b90dcf435fa8bf24eadf 100644 (file)
@@ -18,7 +18,7 @@ import (
 // conversion type-checks the conversion T(x).
 // The result is in x.
 func (check *Checker) conversion(x *operand, T Type) {
-       constArg := x.mode_ == constant_
+       constArg := x.mode() == constant_
 
        constConvertibleTo := func(T Type, val *constant.Value) bool {
                switch t, _ := T.Underlying().(*Basic); {
@@ -113,7 +113,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                        // ok
                } else if isNonTypeParamInterface(T) || constArg && !isConstType(T) || !isTypes2 && x.isNil() {
                        final = Default(x.typ()) // default type of untyped nil is untyped nil
-               } else if x.mode_ == constant_ && isInteger(x.typ()) && allString(T) {
+               } else if x.mode() == constant_ && isInteger(x.typ()) && allString(T) {
                        final = x.typ()
                }
                check.updateExprType(x.expr, final, true)
index 72ecefc7e906abcd8e96e65a9850f39d88bbc870..840452dcc056ff26f45deaf89d9aa0f300ce3e13 100644 (file)
@@ -128,7 +128,7 @@ var op2str2 = [...]string{
 // The unary expression e may be nil. It's passed in for better error messages only.
 func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
        check.expr(nil, x, e.X)
-       if x.mode_ == invalid {
+       if x.mode() == invalid {
                return
        }
 
@@ -137,7 +137,7 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
        case token.AND:
                // spec: "As an exception to the addressability
                // requirement x may also be a composite literal."
-               if _, ok := ast.Unparen(e.X).(*ast.CompositeLit); !ok && x.mode_ != variable {
+               if _, ok := ast.Unparen(e.X).(*ast.CompositeLit); !ok && x.mode() != variable {
                        check.errorf(x, UnaddressableOperand, invalidOp+"cannot take address of %s", x)
                        x.mode_ = invalid
                        return
@@ -173,7 +173,7 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
                return
        }
 
-       if x.mode_ == constant_ {
+       if x.mode() == constant_ {
                if x.val.Kind() == constant.Unknown {
                        // nothing to do (and don't cause an error below in the overflow check)
                        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.mode() == invalid {
                        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.mode() == invalid || isTyped(x.typ()) || !isValid(target) {
                return x.typ(), nil, 0
        }
        // x is untyped
@@ -401,7 +401,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
 
        switch u := target.Underlying().(type) {
        case *Basic:
-               if x.mode_ == constant_ {
+               if x.mode() == constant_ {
                        v, code := check.representation(x, u)
                        if code != 0 {
                                return nil, nil, code
@@ -558,7 +558,7 @@ func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool)
        }
 
        // comparison is ok
-       if x.mode_ == constant_ && y.mode_ == constant_ {
+       if x.mode() == constant_ && y.mode() == constant_ {
                x.val = constant.MakeBool(constant.Compare(x.val, op, y.val))
                // The operands are never materialized; no need to update
                // their types.
@@ -619,7 +619,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
        // TODO(gri) This function seems overly complex. Revisit.
 
        var xval constant.Value
-       if x.mode_ == constant_ {
+       if x.mode() == constant_ {
                xval = constant.ToInt(x.val)
        }
 
@@ -639,7 +639,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
        // Check that constants are representable by uint, but do not convert them
        // (see also go.dev/issue/47243).
        var yval constant.Value
-       if y.mode_ == constant_ {
+       if y.mode() == constant_ {
                // Provide a good error message for negative shift counts.
                yval = constant.ToInt(y.val) // consider -1, 1.0, but not -1.1
                if yval.Kind() == constant.Int && constant.Sign(yval) < 0 {
@@ -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.mode() == invalid {
                                x.mode_ = invalid
                                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.mode() == invalid {
                                x.mode_ = invalid
                                return
                        }
@@ -680,8 +680,8 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                }
        }
 
-       if x.mode_ == constant_ {
-               if y.mode_ == constant_ {
+       if x.mode() == constant_ {
+               if y.mode() == constant_ {
                        // if either x or y has an unknown value, the result is unknown
                        if x.val.Kind() == constant.Unknown || y.val.Kind() == constant.Unknown {
                                x.val = constant.MakeUnknown()
@@ -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.mode() == invalid {
                return
        }
-       if y.mode_ == invalid {
+       if y.mode() == invalid {
                x.mode_ = invalid
                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.mode() == invalid {
                return
        }
 
@@ -832,14 +832,14 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
 
        if op == token.QUO || op == token.REM {
                // check for zero divisor
-               if (x.mode_ == constant_ || allInteger(x.typ())) && y.mode_ == constant_ && constant.Sign(y.val) == 0 {
+               if (x.mode() == constant_ || allInteger(x.typ())) && y.mode() == constant_ && constant.Sign(y.val) == 0 {
                        check.error(&y, DivByZero, invalidOp+"division by zero")
                        x.mode_ = invalid
                        return
                }
 
                // check for divisor underflow in complex division (see go.dev/issue/20227)
-               if x.mode_ == constant_ && y.mode_ == constant_ && isComplex(x.typ()) {
+               if x.mode() == constant_ && y.mode() == constant_ && isComplex(x.typ()) {
                        re, im := constant.Real(y.val), constant.Imag(y.val)
                        re2, im2 := constant.BinaryOp(re, token.MUL, re), constant.BinaryOp(im, token.MUL, im)
                        if constant.Sign(re2) == 0 && constant.Sign(im2) == 0 {
@@ -850,7 +850,7 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
                }
        }
 
-       if x.mode_ == constant_ && y.mode_ == constant_ {
+       if x.mode() == constant_ && y.mode() == constant_ {
                // if either x or y has an unknown value, the result is unknown
                if x.val.Kind() == constant.Unknown || y.val.Kind() == constant.Unknown {
                        x.val = constant.MakeUnknown()
@@ -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.mode() == invalid {
                        return
                }
                check.convertUntyped(y, x.typ())
-               if y.mode_ == invalid {
+               if y.mode() == invalid {
                        x.mode_ = invalid
                        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.mode() == invalid || 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.mode() == invalid {
                        goto Error
                }
 
        case *ast.FuncLit:
                check.funcLit(x, e)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        goto Error
                }
 
        case *ast.CompositeLit:
                check.compositeLit(x, e, hint)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        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.mode() == invalid {
                        goto Error
                }
 
        case *ast.SliceExpr:
                check.sliceExpr(x, e)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        goto Error
                }
 
        case *ast.TypeAssertExpr:
                check.expr(nil, x, e.X)
-               if x.mode_ == invalid {
+               if x.mode() == invalid {
                        goto Error
                }
                // x.(type) expressions are handled explicitly in type switches
@@ -1123,7 +1123,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
 
        case *ast.StarExpr:
                check.exprOrType(x, e.X, false)
-               switch x.mode_ {
+               switch x.mode() {
                case invalid:
                        goto Error
                case typexpr:
@@ -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.mode() == invalid {
                        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.mode() == invalid {
                        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.mode() != invalid {
                // multiple values
                list = make([]*operand, t.Len())
                for i, v := range t.vars {
@@ -1295,9 +1295,9 @@ func (check *Checker) multiExpr(e ast.Expr, allowCommaOk bool) (list []*operand,
 
        // exactly one (possibly invalid or comma-ok) value
        list = []*operand{&x}
-       if allowCommaOk && (x.mode_ == mapindex || x.mode_ == commaok || x.mode_ == commaerr) {
+       if allowCommaOk && (x.mode() == mapindex || x.mode() == commaok || x.mode() == commaerr) {
                x2 := &operand{mode_: value, expr: e, typ_: Typ[UntypedBool]}
-               if x.mode_ == commaerr {
+               if x.mode() == commaerr {
                        x2.typ_ = universeError
                }
                list = append(list, x2)
@@ -1330,10 +1330,10 @@ func (check *Checker) exprOrType(x *operand, e ast.Expr, allowGeneric bool) {
 // exclude reports an error if x.mode is in modeset and sets x.mode to invalid.
 // The modeset may contain any of 1<<novalue, 1<<builtin, 1<<typexpr.
 func (check *Checker) exclude(x *operand, modeset uint) {
-       if modeset&(1<<x.mode_) != 0 {
+       if modeset&(1<<x.mode()) != 0 {
                var msg string
                var code Code
-               switch x.mode_ {
+               switch x.mode() {
                case novalue:
                        if modeset&(1<<typexpr) != 0 {
                                msg = "%s used as value"
@@ -1357,7 +1357,7 @@ func (check *Checker) exclude(x *operand, modeset uint) {
 
 // singleValue reports an error if x describes a tuple and sets x.mode to invalid.
 func (check *Checker) singleValue(x *operand) {
-       if x.mode_ == value {
+       if x.mode() == value {
                // tuple types are never named - no need for underlying type below
                if t, ok := x.typ().(*Tuple); ok {
                        assert(t.Len() != 1)
index 064d16265352fd96d59ca7f5bbed43c1f1d1a60d..8dc46f0783682d6aa75bd4ce9810d8bdbbe6699a 100644 (file)
@@ -20,7 +20,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
        check.exprOrType(x, e.x, true)
        // x may be generic
 
-       switch x.mode_ {
+       switch x.mode() {
        case invalid:
                check.use(e.indices...)
                return false
@@ -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.mode() == invalid {
                return false
        }
 
@@ -77,7 +77,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
        case *Basic:
                if isString(typ) {
                        valid = true
-                       if x.mode_ == constant_ {
+                       if x.mode() == constant_ {
                                length = int64(len(constant.StringVal(x.val)))
                        }
                        // an indexed string always yields a byte value
@@ -90,7 +90,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
        case *Array:
                valid = true
                length = typ.len
-               if x.mode_ != variable {
+               if x.mode() != variable {
                        x.mode_ = value
                }
                x.typ_ = typ.elem
@@ -143,7 +143,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                        case *Array:
                                l = t.len
                                e = t.elem
-                               if x.mode_ != variable {
+                               if x.mode() != variable {
                                        mode = value
                                }
                        case *Pointer:
@@ -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.mode() == invalid {
                check.use(e.Low, e.High, e.Max)
                return
        }
@@ -306,7 +306,7 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
                                return
                        }
                        valid = true
-                       if x.mode_ == constant_ {
+                       if x.mode() == constant_ {
                                length = int64(len(constant.StringVal(x.val)))
                        }
                        // spec: "For untyped string operands the result
@@ -319,7 +319,7 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
        case *Array:
                valid = true
                length = u.len
-               if x.mode_ != variable {
+               if x.mode() != variable {
                        check.errorf(x, NonSliceableOperand, "cannot slice unaddressable value %s", x)
                        x.mode_ = invalid
                        return
@@ -427,7 +427,7 @@ func (check *Checker) index(index ast.Expr, max int64) (typ Type, val int64) {
                return
        }
 
-       if x.mode_ != constant_ {
+       if x.mode() != constant_ {
                return x.typ(), -1
        }
 
@@ -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.mode() == invalid {
                return false
        }
 
        // spec: "a constant index that is untyped is given type int"
        check.convertUntyped(x, Typ[Int])
-       if x.mode_ == invalid {
+       if x.mode() == invalid {
                return false
        }
 
@@ -463,7 +463,7 @@ func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNega
                return false
        }
 
-       if x.mode_ == constant_ {
+       if x.mode() == constant_ {
                // spec: "a constant index must be non-negative ..."
                if !allowNegative && constant.Sign(x.val) < 0 {
                        check.errorf(x, code, invalidArg+"%s %s must not be negative", what, x)
index db960723ca0474effb121a807890e1be191da23a..6a49be707934feb0f1ee5d22a1a73f94cc381fc1 100644 (file)
@@ -65,7 +65,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
        // If we have invalid (ordinary) arguments, an error was reported before.
        // Avoid additional inference errors and exit early (go.dev/issue/60434).
        for _, arg := range args {
-               if arg.mode_ == invalid {
+               if arg.mode() == invalid {
                        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.mode() == invalid {
                        // An error was reported earlier. Ignore this arg
                        // and continue, we may still be able to infer all
                        // targs resulting in fewer follow-on errors.
index 2bcd229358a9c8058e3fef1890257568f088a3eb..11366f1d45151b547d81efabbd4d166eabc9033d 100644 (file)
@@ -66,7 +66,7 @@ func (check *Checker) basicLit(x *operand, e *ast.BasicLit) {
                }
        }
        x.setConst(e.Kind, e.Value)
-       if x.mode_ == invalid {
+       if x.mode() == invalid {
                // 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,10 +265,10 @@ 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.mode() == invalid {
                                continue
                        }
-                       if x.mode_ == constant_ {
+                       if x.mode() == constant_ {
                                duplicate := false
                                xkey := keyVal(x.val)
                                if keyIsInterface {
index 3de2455899dbeb1e5093c725e01c2ebb029e5b34..b5c24a802ccb1f13bdb07e2f0ab13903b69162de 100644 (file)
@@ -64,12 +64,16 @@ type operand struct {
        id    builtinId
 }
 
+func (x *operand) mode() operandMode {
+       return x.mode_
+}
+
 func (x *operand) typ() Type {
        return x.typ_
 }
 
 func (x *operand) isValid() bool {
-       return x.mode_ != invalid
+       return x.mode() != invalid
 }
 
 // Pos returns the position of the expression corresponding to x.
@@ -121,7 +125,7 @@ func (x *operand) Pos() token.Pos {
 func operandString(x *operand, qf Qualifier) string {
        // special-case nil
        if isTypes2 {
-               if x.mode_ == nilvalue {
+               if x.mode() == nilvalue {
                        switch x.typ() {
                        case nil, Typ[Invalid]:
                                return "nil (with invalid type)"
@@ -132,7 +136,7 @@ func operandString(x *operand, qf Qualifier) string {
                        }
                }
        } else { // go/types
-               if x.mode_ == value && x.typ() == Typ[UntypedNil] {
+               if x.mode() == value && x.typ() == Typ[UntypedNil] {
                        return "nil"
                }
        }
@@ -143,7 +147,7 @@ func operandString(x *operand, qf Qualifier) string {
        if x.expr != nil {
                expr = ExprString(x.expr)
        } else {
-               switch x.mode_ {
+               switch x.mode() {
                case builtin:
                        expr = predeclaredFuncs[x.id].name
                case typexpr:
@@ -161,7 +165,7 @@ func operandString(x *operand, qf Qualifier) string {
 
        // <untyped kind>
        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 {
        }
 
        // <mode>
-       buf.WriteString(operandModeString[x.mode_])
+       buf.WriteString(operandModeString[x.mode()])
 
        // <val>
-       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
        }
 
index cbe2c3753589832e628711f40cdf9dfa806d6cf3..05ef827eecafb82312d33e5517137b69e7f7060f 100644 (file)
@@ -37,7 +37,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
        check.hasCallOrRecv = false
        check.expr(nil, &x, rangeVar)
 
-       if isTypes2 && x.mode_ != invalid && sValue == nil && !check.hasCallOrRecv {
+       if isTypes2 && x.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 {
index d440259c282d1d3e2e48827313b008fb8520572d..809246bb0582df5887a6f05cc7b3079cdf1fb997 100644 (file)
@@ -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()
index a449feb220f31226ddda1716bad7b8b4d54f252f..ee2f872577fd75975e0beedd854b833228b7432d 100644 (file)
@@ -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")
                        }
                }
index 848d662f10b3b2550a3264f584c1641fd1f48b78..79b7f6b5ca7b67e743ea3ee0addc71e11f602515 100644 (file)
@@ -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