]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: mechanically rename operand.typ to operand.typ_
authorMark Freeman <mark@golang.org>
Wed, 4 Feb 2026 20:30:17 +0000 (15:30 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 5 Feb 2026 21:43:58 +0000 (13:43 -0800)
Change-Id: Iba87b8bc6188e5e784542f2c0f6f4c4cc3f70b28
Reviewed-on: https://go-review.googlesource.com/c/go/+/742022
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
30 files changed:
src/cmd/compile/internal/types2/api_predicates.go
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/api_predicates.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 d2473804c067a66a44d2bc0667122e38a434c629..a1be5de5f476204d5992da47cb02372534a00830 100644 (file)
@@ -28,7 +28,7 @@ func AssertableTo(V *Interface, T Type) bool {
 // The behavior of AssignableTo is unspecified if V or T is Typ[Invalid] or an
 // uninstantiated generic type.
 func AssignableTo(V, T Type) bool {
-       x := operand{mode: value, typ: V}
+       x := operand{mode: value, typ_: V}
        ok, _ := x.assignableTo(nil, T, nil) // check not needed for non-constant x
        return ok
 }
@@ -39,7 +39,7 @@ func AssignableTo(V, T Type) bool {
 // The behavior of ConvertibleTo is unspecified if V or T is Typ[Invalid] or an
 // uninstantiated generic type.
 func ConvertibleTo(V, T Type) bool {
-       x := operand{mode: value, typ: V}
+       x := operand{mode: value, typ_: V}
        return x.convertibleTo(nil, T, nil) // check not needed for non-constant x
 }
 
index 87f5c8beeafcafaeffeec812a727ea1887337a41..03ad0085ba572d71a6d6c9bed2e24dda659cd8ea 100644 (file)
@@ -37,7 +37,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                return
        }
 
-       if isUntyped(x.typ) {
+       if isUntyped(x.typ_) {
                target := T
                // spec: "If an untyped constant is assigned to a variable of interface
                // type or the blank identifier, the constant is first converted to type
@@ -52,16 +52,16 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                                        return
                                }
                        } else if T == nil || isNonTypeParamInterface(T) {
-                               target = Default(x.typ)
+                               target = Default(x.typ_)
                        }
                } else { // go/types
                        if T == nil || isNonTypeParamInterface(T) {
-                               if T == nil && x.typ == Typ[UntypedNil] {
+                               if T == nil && x.typ_ == Typ[UntypedNil] {
                                        check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
                                        x.mode = invalid
                                        return
                                }
-                               target = Default(x.typ)
+                               target = Default(x.typ_)
                        }
                }
                newType, val, code := check.implicitTypeAndValue(x, target)
@@ -83,15 +83,15 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                        x.val = val
                        check.updateExprVal(x.expr, val)
                }
-               if newType != x.typ {
-                       x.typ = newType
+               if newType != x.typ_ {
+                       x.typ_ = newType
                        check.updateExprType(x.expr, newType, false)
                }
        }
        // x.typ is typed
 
        // A generic (non-instantiated) function value cannot be assigned to a variable.
-       if sig, _ := x.typ.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
+       if sig, _ := x.typ_.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
                check.errorf(x, WrongTypeArgCount, "cannot use generic function %s without instantiation in %s", x, context)
                x.mode = invalid
                return
@@ -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]
                }
@@ -131,11 +131,11 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
                }
                return
        }
-       assert(isConstType(x.typ))
+       assert(isConstType(x.typ_))
 
        // If the lhs doesn't have a type yet, use the type of x.
        if lhs.typ == nil {
-               lhs.typ = x.typ
+               lhs.typ = x.typ_
        }
 
        check.assignment(x, lhs.typ, "constant declaration")
@@ -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]
                }
@@ -161,7 +161,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) {
 
        // If lhs doesn't have a type yet, use the type of x.
        if lhs.typ == nil {
-               typ := x.typ
+               typ := x.typ_
                if isUntyped(typ) {
                        // convert untyped types to default types
                        if typ == Typ[UntypedNil] {
@@ -216,7 +216,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
                check.usedVars[v] = v_used // restore v.used
        }
 
-       if x.mode == invalid || !isValid(x.typ) {
+       if x.mode == invalid || !isValid(x.typ_) {
                return Typ[Invalid]
        }
 
@@ -240,7 +240,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
                return Typ[Invalid]
        }
 
-       return x.typ
+       return x.typ_
 }
 
 // assignVar checks the assignment lhs = rhs (if x == nil), or lhs = x (if x != nil).
@@ -278,7 +278,7 @@ func (check *Checker) assignVar(lhs, rhs syntax.Expr, x *operand, context string
 // operandTypes returns the list of types for the given operands.
 func operandTypes(list []*operand) (res []Type) {
        for _, x := range list {
-               res = append(res, x.typ)
+               res = append(res, x.typ_)
        }
        return res
 }
index 5fa0e6c6f04a660f2dd024dedeb0bbcdd0d26785..b544dd94f0075ad311d6a3477fbf0cb8a3e257bf 100644 (file)
@@ -109,7 +109,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
                                y := args[1]
                                hasString := false
-                               for _, u := range typeset(y.typ) {
+                               for _, u := range typeset(y.typ_) {
                                        if s, _ := u.(*Slice); s != nil && Identical(s.elem, universeByte) {
                                                // typeset ⊇ {[]byte}
                                        } else if isString(u) {
@@ -122,7 +122,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                }
                                if y != nil && hasString {
                                        // setting the signature also signals that we're done
-                                       sig = makeSig(x.typ, x.typ, y.typ)
+                                       sig = makeSig(x.typ_, x.typ_, y.typ_)
                                        sig.variadic = true
                                }
                        }
@@ -131,7 +131,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // general case
                if sig == nil {
                        // check arguments by creating custom signature
-                       sig = makeSig(x.typ, x.typ, NewSlice(E)) // []E required for variadic signature
+                       sig = makeSig(x.typ_, x.typ_, NewSlice(E)) // []E required for variadic signature
                        sig.variadic = true
                        check.arguments(call, sig, nil, nil, args, nil) // discard result (we know the result type)
                        // ok to continue even if check.arguments reported errors
@@ -148,7 +148,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // len(x)
                mode := invalid
                var val constant.Value
-               switch t := arrayPtrDeref(x.typ.Underlying()).(type) {
+               switch t := arrayPtrDeref(x.typ_.Underlying()).(type) {
                case *Basic:
                        if isString(t) && id == _Len {
                                if x.mode == constant_ {
@@ -183,10 +183,10 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        }
 
                case *Interface:
-                       if !isTypeParam(x.typ) {
+                       if !isTypeParam(x.typ_) {
                                break
                        }
-                       if underIs(x.typ, func(u Type) bool {
+                       if underIs(x.typ_, func(u Type) bool {
                                switch t := arrayPtrDeref(u).(type) {
                                case *Basic:
                                        if isString(t) && id == _Len {
@@ -207,7 +207,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
                if mode == invalid {
                        // avoid error if underlying type is invalid
-                       if isValid(x.typ.Underlying()) {
+                       if isValid(x.typ_.Underlying()) {
                                code := InvalidCap
                                if id == _Len {
                                        code = InvalidLen
@@ -219,18 +219,18 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
                // record the signature before changing x.typ
                if check.recordTypes() && mode != constant_ {
-                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ_))
                }
 
                x.mode = mode
-               x.typ = Typ[Int]
+               x.typ_ = Typ[Int]
                x.val = val
 
        case _Clear:
                // clear(m)
                check.verifyVersionf(call.Fun, go1_21, "clear")
 
-               if !underIs(x.typ, func(u Type) bool {
+               if !underIs(x.typ_, func(u Type) bool {
                        switch u.(type) {
                        case *Map, *Slice:
                                return true
@@ -243,12 +243,12 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
                x.mode = novalue
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ_))
                }
 
        case _Close:
                // close(c)
-               if !underIs(x.typ, func(u Type) bool {
+               if !underIs(x.typ_, func(u Type) bool {
                        uch, _ := u.(*Chan)
                        if uch == nil {
                                check.errorf(x, InvalidClose, invalidOp+"cannot close non-channel %s", x)
@@ -264,7 +264,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
                x.mode = novalue
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ_))
                }
 
        case _Complex:
@@ -273,10 +273,10 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
                // convert or check untyped arguments
                d := 0
-               if isUntyped(x.typ) {
+               if isUntyped(x.typ_) {
                        d |= 1
                }
-               if isUntyped(y.typ) {
+               if isUntyped(y.typ_) {
                        d |= 2
                }
                switch d {
@@ -284,10 +284,10 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        // x and y are typed => nothing to do
                case 1:
                        // only x is untyped => convert to type of y
-                       check.convertUntyped(x, y.typ)
+                       check.convertUntyped(x, y.typ_)
                case 2:
                        // only y is untyped => convert to type of x
-                       check.convertUntyped(y, x.typ)
+                       check.convertUntyped(y, x.typ_)
                case 3:
                        // x and y are untyped =>
                        // 1) if both are constants, convert them to untyped
@@ -299,8 +299,8 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        //    because shifts of floats are not permitted)
                        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]
+                                       if isNumeric(x.typ_) && constant.Sign(constant.Imag(x.val)) == 0 {
+                                               x.typ_ = Typ[UntypedFloat]
                                        }
                                }
                                toFloat(x)
@@ -317,8 +317,8 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                // both argument types must be identical
-               if !Identical(x.typ, y.typ) {
-                       check.errorf(x, InvalidComplex, invalidOp+"%v (mismatched types %s and %s)", call, x.typ, y.typ)
+               if !Identical(x.typ_, y.typ_) {
+                       check.errorf(x, InvalidComplex, invalidOp+"%v (mismatched types %s and %s)", call, x.typ_, y.typ_)
                        return
                }
 
@@ -340,7 +340,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
                resTyp := check.applyTypeFunc(f, x, id)
                if resTyp == nil {
-                       check.errorf(x, InvalidComplex, invalidArg+"arguments have type %s, expected floating-point", x.typ)
+                       check.errorf(x, InvalidComplex, invalidArg+"arguments have type %s, expected floating-point", x.typ_)
                        return
                }
 
@@ -352,10 +352,10 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                if check.recordTypes() && x.mode != constant_ {
-                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ_, x.typ_))
                }
 
-               x.typ = resTyp
+               x.typ_ = resTyp
 
        case _Copy:
                // copy(x, y []E) int
@@ -372,7 +372,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                var special bool
                if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
                        special = true
-                       for _, u := range typeset(y.typ) {
+                       for _, u := range typeset(y.typ_) {
                                if s, _ := u.(*Slice); s != nil && Identical(s.elem, universeByte) {
                                        // typeset ⊇ {[]byte}
                                } else if isString(u) {
@@ -396,7 +396,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        srcE, err := sliceElem(y)
                        if err != nil {
                                // If we have a string, for a better error message proceed with byte element type.
-                               if !allString(y.typ) {
+                               if !allString(y.typ_) {
                                        check.errorf(y, InvalidCopy, "invalid copy: %s", err.format(check))
                                        return
                                }
@@ -409,16 +409,16 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ, y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ_, y.typ_))
                }
                x.mode = value
-               x.typ = Typ[Int]
+               x.typ_ = Typ[Int]
 
        case _Delete:
                // delete(map_, key)
                // map_ must be a map type or a type parameter describing map types.
                // The key cannot be a type parameter for now.
-               map_ := x.typ
+               map_ := x.typ_
                var key Type
                if !underIs(map_, func(u Type) bool {
                        map_, _ := u.(*Map)
@@ -452,12 +452,12 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // real(complexT) floatT
 
                // convert or check untyped argument
-               if isUntyped(x.typ) {
+               if isUntyped(x.typ_) {
                        if x.mode == constant_ {
                                // an untyped constant number can always be considered
                                // as a complex constant
-                               if isNumeric(x.typ) {
-                                       x.typ = Typ[UntypedComplex]
+                               if isNumeric(x.typ_) {
+                                       x.typ_ = Typ[UntypedComplex]
                                }
                        } else {
                                // an untyped non-constant argument may appear if
@@ -494,7 +494,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        if id == _Real {
                                code = InvalidReal
                        }
-                       check.errorf(x, code, invalidArg+"argument has type %s, expected complex type", x.typ)
+                       check.errorf(x, code, invalidArg+"argument has type %s, expected complex type", x.typ_)
                        return
                }
 
@@ -510,10 +510,10 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                if check.recordTypes() && x.mode != constant_ {
-                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ_))
                }
 
-               x.typ = resTyp
+               x.typ_ = resTyp
 
        case _Make:
                // make(T, n)
@@ -569,9 +569,9 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        // safe to continue
                }
                x.mode = value
-               x.typ = T
+               x.typ_ = T
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, types...))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, types...))
                }
 
        case _Max, _Min:
@@ -589,7 +589,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                return
                        }
 
-                       if !allOrdered(a.typ) {
+                       if !allOrdered(a.typ_) {
                                check.errorf(a, InvalidMinMaxOperand, invalidArg+"%s cannot be ordered", a)
                                return
                        }
@@ -601,8 +601,8 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                        return
                                }
 
-                               if !Identical(x.typ, a.typ) {
-                                       check.errorf(a, MismatchedTypes, invalidArg+"mismatched types %s (previous argument) and %s (type of %s)", x.typ, a.typ, a.expr)
+                               if !Identical(x.typ_, a.typ_) {
+                                       check.errorf(a, MismatchedTypes, invalidArg+"mismatched types %s (previous argument) and %s (type of %s)", x.typ_, a.typ_, a.expr)
                                        return
                                }
 
@@ -628,15 +628,15 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
                // Use the final type computed above for all arguments.
                for _, a := range args {
-                       check.updateExprType(a.expr, x.typ, true)
+                       check.updateExprType(a.expr, x.typ_, true)
                }
 
                if check.recordTypes() && x.mode != constant_ {
                        types := make([]Type, nargs)
                        for i := range types {
-                               types[i] = x.typ
+                               types[i] = x.typ_
                        }
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, types...))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, types...))
                }
 
        case _New:
@@ -650,26 +650,26 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        return
                case typexpr:
                        // new(T)
-                       check.validVarType(arg, x.typ)
+                       check.validVarType(arg, x.typ_)
                default:
                        // new(expr)
-                       if isUntyped(x.typ) {
+                       if isUntyped(x.typ_) {
                                // check for overflow and untyped nil
                                check.assignment(x, nil, "argument to new")
                                if x.mode == invalid {
                                        return
                                }
-                               assert(isTyped(x.typ))
+                               assert(isTyped(x.typ_))
                        }
                        // report version error only if there are no other errors
                        check.verifyVersionf(call.Fun, go1_26, "new(%s)", arg)
                }
 
-               T := x.typ
+               T := x.typ_
                x.mode = value
-               x.typ = NewPointer(T)
+               x.typ_ = NewPointer(T)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, T))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, T))
                }
 
        case _Panic:
@@ -708,7 +708,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                if a.mode == invalid {
                                        return
                                }
-                               params[i] = a.typ
+                               params[i] = a.typ_
                        }
                }
 
@@ -720,9 +720,9 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
        case _Recover:
                // recover() interface{}
                x.mode = value
-               x.typ = &emptyInterface
+               x.typ_ = &emptyInterface
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_))
                }
 
        case _Add:
@@ -740,9 +740,9 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                x.mode = value
-               x.typ = Typ[UnsafePointer]
+               x.typ_ = Typ[UnsafePointer]
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, x.typ, y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, x.typ_, y.typ_))
                }
 
        case _Alignof:
@@ -752,17 +752,17 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        return
                }
 
-               if check.hasVarSize(x.typ) {
+               if check.hasVarSize(x.typ_) {
                        x.mode = value
                        if check.recordTypes() {
-                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ))
+                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ_))
                        }
                } else {
                        x.mode = constant_
-                       x.val = constant.MakeInt64(check.conf.alignof(x.typ))
+                       x.val = constant.MakeInt64(check.conf.alignof(x.typ_))
                        // result is constant - no need to record signature
                }
-               x.typ = Typ[Uintptr]
+               x.typ_ = Typ[Uintptr]
 
        case _Offsetof:
                // unsafe.Offsetof(x T) uintptr, where x must be a selector
@@ -780,7 +780,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        return
                }
 
-               base := derefStructPtr(x.typ)
+               base := derefStructPtr(x.typ_)
                sel := selx.Sel.Value
                obj, index, indirect := lookupFieldOrMethod(base, false, check.pkg, sel, false)
                switch obj.(type) {
@@ -831,7 +831,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        x.val = constant.MakeInt64(offs)
                        // result is constant - no need to record signature
                }
-               x.typ = Typ[Uintptr]
+               x.typ_ = Typ[Uintptr]
 
        case _Sizeof:
                // unsafe.Sizeof(x T) uintptr
@@ -840,13 +840,13 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        return
                }
 
-               if check.hasVarSize(x.typ) {
+               if check.hasVarSize(x.typ_) {
                        x.mode = value
                        if check.recordTypes() {
-                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ))
+                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ_))
                        }
                } else {
-                       size := check.conf.sizeof(x.typ)
+                       size := check.conf.sizeof(x.typ_)
                        if size < 0 {
                                check.errorf(x, TypeTooLarge, "%s is too large", x)
                                return
@@ -855,13 +855,13 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        x.val = constant.MakeInt64(size)
                        // result is constant - no need to record signature
                }
-               x.typ = Typ[Uintptr]
+               x.typ_ = Typ[Uintptr]
 
        case _Slice:
                // unsafe.Slice(ptr *T, len IntegerType) []T
                check.verifyVersionf(call.Fun, go1_17, "unsafe.Slice")
 
-               u, _ := commonUnder(x.typ, nil)
+               u, _ := commonUnder(x.typ_, nil)
                ptr, _ := u.(*Pointer)
                if ptr == nil {
                        check.errorf(x, InvalidUnsafeSlice, invalidArg+"%s is not a pointer", x)
@@ -874,16 +874,16 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                x.mode = value
-               x.typ = NewSlice(ptr.base)
+               x.typ_ = NewSlice(ptr.base)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, ptr, y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, ptr, y.typ_))
                }
 
        case _SliceData:
                // unsafe.SliceData(slice []T) *T
                check.verifyVersionf(call.Fun, go1_20, "unsafe.SliceData")
 
-               u, _ := commonUnder(x.typ, nil)
+               u, _ := commonUnder(x.typ_, nil)
                slice, _ := u.(*Slice)
                if slice == nil {
                        check.errorf(x, InvalidUnsafeSliceData, invalidArg+"%s is not a slice", x)
@@ -891,9 +891,9 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                x.mode = value
-               x.typ = NewPointer(slice.elem)
+               x.typ_ = NewPointer(slice.elem)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, slice))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, slice))
                }
 
        case _String:
@@ -911,9 +911,9 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                x.mode = value
-               x.typ = Typ[String]
+               x.typ_ = Typ[String]
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, NewPointer(universeByte), y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, NewPointer(universeByte), y.typ_))
                }
 
        case _StringData:
@@ -926,16 +926,16 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                }
 
                x.mode = value
-               x.typ = NewPointer(universeByte)
+               x.typ_ = NewPointer(universeByte)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, Typ[String]))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, Typ[String]))
                }
 
        case _Assert:
                // 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
                }
@@ -984,7 +984,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 // or a type error if x is not a slice (or a type set of slices).
 func sliceElem(x *operand) (Type, *typeError) {
        var E Type
-       for _, u := range typeset(x.typ) {
+       for _, u := range typeset(x.typ_) {
                s, _ := u.(*Slice)
                if s == nil {
                        if x.isNil() {
@@ -1070,7 +1070,7 @@ func (check *Checker) hasVarSize(t Type) bool {
 // applyTypeFunc returns nil.
 // If x is not a type parameter, the result is f(x).
 func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId) Type {
-       if tp, _ := Unalias(x.typ).(*TypeParam); tp != nil {
+       if tp, _ := Unalias(x.typ_).(*TypeParam); tp != nil {
                // Test if t satisfies the requirements for the argument
                // type and collect possible result types at the same time.
                var terms []*Term
@@ -1114,7 +1114,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                return ptyp
        }
 
-       return f(x.typ)
+       return f(x.typ_)
 }
 
 // makeSig makes a signature for the given argument and result types.
index cf950959f9f7cc68b4ee42eff58635d93b43e3c9..f1727d8de1d97dfecacb73ba07e60d6434d04294 100644 (file)
@@ -58,7 +58,7 @@ func (check *Checker) funcInst(T *target, pos syntax.Pos, x *operand, inst *synt
        // Check the number of type arguments (got) vs number of type parameters (want).
        // Note that x is a function value, not a type expression, so we don't need to
        // call Underlying below.
-       sig := x.typ.(*Signature)
+       sig := x.typ_.(*Signature)
        got, want := len(targs), sig.TypeParams().Len()
        if got > want {
                // Providing too many type arguments is always an error.
@@ -99,7 +99,7 @@ func (check *Checker) funcInst(T *target, pos syntax.Pos, x *operand, inst *synt
                        // or the result type in a return statement. Create a pseudo-expression for that operand
                        // that makes sense when reported in error messages from infer, below.
                        expr := syntax.NewName(x.Pos(), T.desc)
-                       args = []*operand{{mode: value, expr: expr, typ: T.sig}}
+                       args = []*operand{{mode: value, expr: expr, typ_: T.sig}}
                        reverse = true
                }
 
@@ -123,7 +123,7 @@ func (check *Checker) funcInst(T *target, pos syntax.Pos, x *operand, inst *synt
        // instantiate function signature
        sig = check.instantiateSignature(x.Pos(), x.expr, sig, targs, xlist)
 
-       x.typ = sig
+       x.typ_ = sig
        x.mode = value
        return nil
 }
@@ -197,7 +197,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                if x.mode == invalid {
                        return conversion
                }
-               T := x.typ
+               T := x.typ_
                x.mode = invalid
                // We cannot convert a value to an incomplete type; make sure it's complete.
                if !check.isComplete(T) {
@@ -249,7 +249,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
 
        // 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.
-       u, err := commonUnder(x.typ, func(t, u Type) *typeError {
+       u, err := commonUnder(x.typ_, func(t, u Type) *typeError {
                if _, ok := u.(*Signature); u != nil && !ok {
                        return typeErrorf("%s is not a function", t)
                }
@@ -331,17 +331,17 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                        x.expr = call
                        return statement
                }
-               x.typ = typ
+               x.typ_ = typ
        default:
                x.mode = value
-               x.typ = sig.results
+               x.typ_ = sig.results
        }
        x.expr = call
        check.hasCallOrRecv = true
 
        // 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
        }
 
@@ -380,7 +380,7 @@ func (check *Checker) genericExprList(elist []syntax.Expr) (resList []*operand,
                                if i < len(targsList) {
                                        if n := len(targsList[i]); n > 0 {
                                                // x must be a partially instantiated function
-                                               assert(n < x.typ.(*Signature).TypeParams().Len())
+                                               assert(n < x.typ_.(*Signature).TypeParams().Len())
                                        }
                                }
                        }
@@ -417,11 +417,11 @@ 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 {
-                                       resList[i] = &operand{mode: value, expr: e, typ: v.typ}
+                                       resList[i] = &operand{mode: value, expr: e, typ_: v.typ}
                                }
                        } else {
                                // x is exactly one value (possibly invalid or uninstantiated generic function).
@@ -580,7 +580,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
        if enableReverseTypeInference {
                for i, arg := range args {
                        // generic arguments cannot have a defined (*Named) type - no need for underlying type below
-                       if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
+                       if asig, _ := arg.typ_.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
                                // The argument type is a generic function signature. This type is
                                // pointer-identical with (it's copied from) the type of the generic
                                // function argument and thus the function object.
@@ -595,7 +595,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
                                atparams, tmp := check.renameTParams(call.Pos(), asig.TypeParams().list(), asig)
                                asig = tmp.(*Signature)
                                asig.tparams = &TypeParamList{atparams} // renameTParams doesn't touch associated type parameters
-                               arg.typ = asig                          // new type identity for the function argument
+                               arg.typ_ = asig                         // new type identity for the function argument
                                tparams = append(tparams, atparams...)
                                // add partial list of type arguments, if any
                                if i < len(atargs) {
@@ -650,11 +650,11 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
                j := n
                for _, i := range genericArgs {
                        arg := args[i]
-                       asig := arg.typ.(*Signature)
+                       asig := arg.typ_.(*Signature)
                        k := j + asig.TypeParams().Len()
                        // targs[j:k] are the inferred type arguments for asig
-                       arg.typ = check.instantiateSignature(call.Pos(), arg.expr, asig, targs[j:k], nil) // TODO(gri) provide xlist if possible (partial instantiations)
-                       check.record(arg)                                                                 // record here because we didn't use the usual expr evaluators
+                       arg.typ_ = check.instantiateSignature(call.Pos(), arg.expr, asig, targs[j:k], nil) // TODO(gri) provide xlist if possible (partial instantiations)
+                       check.record(arg)                                                                  // record here because we didn't use the usual expr evaluators
                        j = k
                }
        }
@@ -756,27 +756,27 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
                        case *Const:
                                assert(exp.Val() != nil)
                                x.mode = constant_
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                x.val = exp.val
                        case *TypeName:
                                x.mode = typexpr
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                        case *Var:
                                x.mode = variable
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                if pkg.cgo && strings.HasPrefix(exp.name, "_Cvar_") {
-                                       x.typ = x.typ.(*Pointer).base
+                                       x.typ_ = x.typ_.(*Pointer).base
                                }
                        case *Func:
                                x.mode = funcMode
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                if pkg.cgo && strings.HasPrefix(exp.name, "_Cmacro_") {
                                        x.mode = value
-                                       x.typ = x.typ.(*Signature).results.vars[0].typ
+                                       x.typ_ = x.typ_.(*Signature).results.vars[0].typ
                                }
                        case *Builtin:
                                x.mode = builtin
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                x.id = exp.id
                        default:
                                check.dump("%v: unexpected object %v", atPos(e.Sel), exp)
@@ -797,7 +797,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
        }
 
        // We cannot select on an incomplete type; make sure it's complete.
-       if !check.isComplete(x.typ) {
+       if !check.isComplete(x.typ_) {
                goto Error
        }
 
@@ -818,14 +818,14 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
 
        // Additionally, if x.typ is a pointer type, selecting implicitly dereferences the value, meaning
        // its base type must also be complete.
-       if p, ok := x.typ.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
+       if p, ok := x.typ_.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
                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()) {
+               if !isValid(x.typ_.Underlying()) {
                        goto Error
                }
 
@@ -837,19 +837,19 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
 
                if indirect {
                        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)
+                               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)
+                               check.errorf(e.Sel, InvalidMethodExpr, "cannot call pointer method %s on %s", sel, x.typ_)
                        }
                        goto Error
                }
 
                var why string
-               if isInterfacePtr(x.typ) {
-                       why = check.interfacePtrError(x.typ)
+               if isInterfacePtr(x.typ_) {
+                       why = check.interfacePtrError(x.typ_)
                } else {
-                       alt, _, _ := lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel, true)
-                       why = check.lookupError(x.typ, sel, alt, false)
+                       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)
                goto Error
@@ -859,18 +859,18 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
        switch obj := obj.(type) {
        case *Var:
                if x.mode == typexpr {
-                       check.errorf(e.X, MissingFieldOrMethod, "operand for field selector %s must be value of type %s", sel, x.typ)
+                       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)
+               check.recordSelection(e, FieldVal, x.typ_, obj, index, indirect)
                if x.mode == variable || indirect {
                        x.mode = variable
                } else {
                        x.mode = value
                }
-               x.typ = obj.typ
+               x.typ_ = obj.typ
 
        case *Func:
                check.objDecl(obj) // ensure fully set-up signature
@@ -878,7 +878,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
 
                if x.mode == typexpr {
                        // method expression
-                       check.recordSelection(e, MethodExpr, x.typ, obj, index, indirect)
+                       check.recordSelection(e, MethodExpr, x.typ_, obj, index, indirect)
 
                        sig := obj.typ.(*Signature)
                        if sig.recv == nil {
@@ -906,9 +906,9 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
                                        name = "_"
                                }
                        }
-                       params = append([]*Var{NewParam(sig.recv.pos, sig.recv.pkg, name, x.typ)}, params...)
+                       params = append([]*Var{NewParam(sig.recv.pos, sig.recv.pkg, name, x.typ_)}, params...)
                        x.mode = value
-                       x.typ = &Signature{
+                       x.typ_ = &Signature{
                                tparams:  sig.tparams,
                                params:   NewTuple(params...),
                                results:  sig.results,
@@ -919,14 +919,14 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
 
                        // TODO(gri) If we needed to take into account the receiver's
                        // addressability, should we report the type &(x.typ) instead?
-                       check.recordSelection(e, MethodVal, x.typ, obj, index, indirect)
+                       check.recordSelection(e, MethodVal, x.typ_, obj, index, indirect)
 
                        x.mode = value
 
                        // remove receiver
                        sig := *obj.typ.(*Signature)
                        sig.recv = nil
-                       x.typ = &sig
+                       x.typ_ = &sig
                }
 
        default:
@@ -939,7 +939,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, wantType bool
 
 Error:
        x.mode = invalid
-       x.typ = Typ[Invalid]
+       x.typ_ = Typ[Invalid]
        x.expr = e
 }
 
index b68d72de4d27f4ebfada127f1d3e227b097cd0c8..05190a6bc7ce5c1ef82958df2238687702c6ead1 100644 (file)
@@ -32,8 +32,8 @@ func (check *Checker) overflow(x *operand, opPos syntax.Pos) {
        // their type after each constant operation.
        // x.typ cannot be a type parameter (type
        // parameters cannot be constant types).
-       if isTyped(x.typ) {
-               check.representable(x, x.typ.Underlying().(*Basic))
+       if isTyped(x.typ_) {
+               check.representable(x, x.typ_.Underlying().(*Basic))
                return
        }
 
@@ -253,7 +253,7 @@ func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, Co
        assert(x.mode == constant_)
        v := x.val
        if !representableConst(x.val, check, typ, &v) {
-               if isNumeric(x.typ) && isNumeric(typ) {
+               if isNumeric(x.typ_) && isNumeric(typ) {
                        // numeric conversion : error msg
                        //
                        // integer -> integer : overflows
@@ -261,7 +261,7 @@ func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, Co
                        // float   -> integer : truncated
                        // float   -> float   : overflows
                        //
-                       if !isInteger(x.typ) && isInteger(typ) {
+                       if !isInteger(x.typ_) && isInteger(typ) {
                                return nil, TruncatedFloat
                        } else {
                                return nil, NumericOverflow
@@ -299,8 +299,8 @@ func (check *Checker) convertUntyped(x *operand, target Type) {
                x.val = val
                check.updateExprVal(x.expr, val)
        }
-       if newType != x.typ {
-               x.typ = newType
+       if newType != x.typ_ {
+               x.typ_ = newType
                check.updateExprType(x.expr, newType, false)
        }
 }
index d0920d7ef1006d75a8f0110c7b4b4ddd31c2bc95..cbc4fe964bbe3a77074534c7d1364d99c3dbfef0 100644 (file)
@@ -23,7 +23,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                        // nothing to do
                case representableConst(x.val, check, t, val):
                        return true
-               case isInteger(x.typ) && isString(t):
+               case isInteger(x.typ_) && isString(t):
                        codepoint := unicode.ReplacementChar
                        if i, ok := constant.Uint64Val(x.val); ok && i <= unicode.MaxRune {
                                codepoint = rune(i)
@@ -45,7 +45,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                // A conversion from an integer constant to an integer type
                // can only fail if there's overflow. Give a concise error.
                // (go.dev/issue/63563)
-               if !ok && isInteger(x.typ) && isInteger(T) {
+               if !ok && isInteger(x.typ_) && isInteger(T) {
                        check.errorf(x, InvalidConversion, "constant %s overflows %s", x.val, T)
                        x.mode = invalid
                        return
@@ -62,11 +62,11 @@ func (check *Checker) conversion(x *operand, T Type) {
                                cause = check.sprintf("%s does not contain specific types", T)
                                return false
                        }
-                       if isString(x.typ) && isBytesOrRunes(u) {
+                       if isString(x.typ_) && isBytesOrRunes(u) {
                                return true
                        }
                        if !constConvertibleTo(u, nil) {
-                               if isInteger(x.typ) && isInteger(u) {
+                               if isInteger(x.typ_) && isInteger(u) {
                                        // see comment above on constant conversion
                                        cause = check.sprintf("constant %s overflows %s (in %s)", x.val, u, T)
                                } else {
@@ -96,7 +96,7 @@ func (check *Checker) conversion(x *operand, T Type) {
        // The conversion argument types are final. For untyped values the
        // conversion provides the type, per the spec: "A constant may be
        // given a type explicitly by a constant declaration or conversion,...".
-       if isUntyped(x.typ) {
+       if isUntyped(x.typ_) {
                final := T
                // - For conversions to interfaces, except for untyped nil arguments
                //   and isTypes2, use the argument's default type.
@@ -106,17 +106,17 @@ func (check *Checker) conversion(x *operand, T Type) {
                // - If !isTypes2, keep untyped nil for untyped nil arguments.
                // - For constant integer to string conversions, keep the argument type.
                //   (See also the TODO below.)
-               if isTypes2 && x.typ == Typ[UntypedNil] {
+               if isTypes2 && x.typ_ == Typ[UntypedNil] {
                        // 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) {
-                       final = x.typ
+                       final = Default(x.typ_) // default type of untyped nil is untyped nil
+               } else if x.mode == constant_ && isInteger(x.typ_) && allString(T) {
+                       final = x.typ_
                }
                check.updateExprType(x.expr, final, true)
        }
 
-       x.typ = T
+       x.typ_ = T
 }
 
 // TODO(gri) convertibleTo checks if T(x) is valid. It assumes that the type
@@ -140,7 +140,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
        }
 
        origT := T
-       V := Unalias(x.typ)
+       V := Unalias(x.typ_)
        T = Unalias(T)
        Vu := V.Underlying()
        Tu := T.Underlying()
@@ -250,7 +250,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
                        if V == nil {
                                return false // no specific types
                        }
-                       x.typ = V.typ
+                       x.typ_ = V.typ
                        return Tp.is(func(T *term) bool {
                                if T == nil {
                                        return false // no specific types
@@ -268,7 +268,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
                        if V == nil {
                                return false // no specific types
                        }
-                       x.typ = V.typ
+                       x.typ_ = V.typ
                        if !x.convertibleTo(check, T, cause) {
                                errorf("cannot convert %s (in %s) to type %s", V.typ, Vp, origT)
                                return false
@@ -281,7 +281,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
                                return false // no specific types
                        }
                        if !x.convertibleTo(check, T.typ, cause) {
-                               errorf("cannot convert %s to type %s (in %s)", x.typ, T.typ, Tp)
+                               errorf("cannot convert %s to type %s (in %s)", x.typ_, T.typ, Tp)
                                return false
                        }
                        return true
index 81aeb5ffd00ceffc019265709cc1423ad970d621..49b24b48df2a09f25c052bfef94eda79fc3101da 100644 (file)
@@ -72,7 +72,7 @@ func init() {
 
 func (check *Checker) op(m opPredicates, x *operand, op syntax.Operator) bool {
        if pred := m[op]; pred != nil {
-               if !pred(x.typ) {
+               if !pred(x.typ_) {
                        check.errorf(x, UndefinedOp, invalidOp+"operator %s not defined on %s", op, x)
                        return false
                }
@@ -144,14 +144,14 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
                        return
                }
                x.mode = value
-               x.typ = &Pointer{base: x.typ}
+               x.typ_ = &Pointer{base: x.typ_}
                return
 
        case syntax.Recv:
                // We cannot receive a value with an incomplete type; make sure it's complete.
                if elem := check.chanElem(x, x, true); elem != nil && check.isComplete(elem) {
                        x.mode = commaok
-                       x.typ = elem
+                       x.typ_ = elem
                        check.hasCallOrRecv = true
                        return
                }
@@ -160,7 +160,7 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
 
        case syntax.Tilde:
                // Provide a better error position and message than what check.op below would do.
-               if !allInteger(x.typ) {
+               if !allInteger(x.typ_) {
                        check.error(e, UndefinedOp, "cannot use ~ outside of interface or type constraint")
                        x.mode = invalid
                        return
@@ -180,8 +180,8 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
                        return
                }
                var prec uint
-               if isUnsigned(x.typ) {
-                       prec = uint(check.conf.sizeof(x.typ) * 8)
+               if isUnsigned(x.typ_) {
+                       prec = uint(check.conf.sizeof(x.typ_) * 8)
                }
                x.val = constant.UnaryOp(op2tok[op], x.val, prec)
                x.expr = e
@@ -197,7 +197,7 @@ func (check *Checker) unary(x *operand, e *syntax.Operation) {
 // or send to x (recv == false) operation. If the operation is not valid, chanElem
 // reports an error and returns nil.
 func (check *Checker) chanElem(pos poser, x *operand, recv bool) Type {
-       u, err := commonUnder(x.typ, func(t, u Type) *typeError {
+       u, err := commonUnder(x.typ_, func(t, u Type) *typeError {
                if u == nil {
                        return typeErrorf("no specific channel type")
                }
@@ -220,14 +220,14 @@ func (check *Checker) chanElem(pos poser, x *operand, recv bool) Type {
 
        cause := err.format(check)
        if recv {
-               if isTypeParam(x.typ) {
+               if isTypeParam(x.typ_) {
                        check.errorf(pos, InvalidReceive, invalidOp+"cannot receive from %s: %s", x, cause)
                } else {
                        // In this case, only the non-channel and send-only channel error are possible.
                        check.errorf(pos, InvalidReceive, invalidOp+"cannot receive from %s %s", cause, x)
                }
        } else {
-               if isTypeParam(x.typ) {
+               if isTypeParam(x.typ_) {
                        check.errorf(pos, InvalidSend, invalidOp+"cannot send to %s: %s", x, cause)
                } else {
                        // In this case, only the non-channel and receive-only channel error are possible.
@@ -411,21 +411,21 @@ 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) {
-               return x.typ, nil, 0
+       if x.mode == invalid || isTyped(x.typ_) || !isValid(target) {
+               return x.typ_, nil, 0
        }
        // x is untyped
 
        if isUntyped(target) {
                // both x and target are untyped
-               if m := maxType(x.typ, target); m != nil {
+               if m := maxType(x.typ_, target); m != nil {
                        return m, nil, 0
                }
                return nil, nil, InvalidUntypedConversion
        }
 
        if x.isNil() {
-               assert(isUntyped(x.typ))
+               assert(isUntyped(x.typ_))
                if hasNil(target) {
                        return target, nil, 0
                }
@@ -445,7 +445,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
                // result of comparisons (untyped bool), intermediate
                // (delayed-checked) rhs operands of shifts, and as
                // the value nil.
-               switch x.typ.(*Basic).kind {
+               switch x.typ_.(*Basic).kind {
                case UntypedBool:
                        if !isBoolean(target) {
                                return nil, nil, InvalidUntypedConversion
@@ -483,7 +483,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
                if !u.Empty() {
                        return nil, nil, InvalidUntypedConversion // cannot assign untyped values to non-empty interfaces
                }
-               return Default(x.typ), nil, 0 // default type for nil is nil
+               return Default(x.typ_), nil, 0 // default type for nil is nil
        default:
                return nil, nil, InvalidUntypedConversion
        }
@@ -493,7 +493,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
 // If switchCase is true, the operator op is ignored.
 func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase bool) {
        // Avoid spurious errors if any of the operands has an invalid type (go.dev/issue/54405).
-       if !isValid(x.typ) || !isValid(y.typ) {
+       if !isValid(x.typ_) || !isValid(y.typ_) {
                x.mode = invalid
                return
        }
@@ -508,16 +508,16 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase b
        // spec: "In any comparison, the first operand must be assignable
        // to the type of the second operand, or vice versa."
        code := MismatchedTypes
-       ok, _ := x.assignableTo(check, y.typ, nil)
+       ok, _ := x.assignableTo(check, y.typ_, nil)
        if !ok {
-               ok, _ = y.assignableTo(check, x.typ, nil)
+               ok, _ = y.assignableTo(check, x.typ_, nil)
        }
        if !ok {
                // Report the error on the 2nd operand since we only
                // know after seeing the 2nd operand whether we have
                // a type mismatch.
                errOp = y
-               cause = check.sprintf("mismatched types %s and %s", x.typ, y.typ)
+               cause = check.sprintf("mismatched types %s and %s", x.typ_, y.typ_)
                goto Error
        }
 
@@ -529,9 +529,9 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase b
                switch {
                case x.isNil() || y.isNil():
                        // Comparison against nil requires that the other operand type has nil.
-                       typ := x.typ
+                       typ := x.typ_
                        if x.isNil() {
-                               typ = y.typ
+                               typ = y.typ_
                        }
                        if !hasNil(typ) {
                                // This case should only be possible for "nil == nil".
@@ -542,24 +542,24 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase b
                                goto Error
                        }
 
-               case !Comparable(x.typ):
+               case !Comparable(x.typ_):
                        errOp = x
-                       cause = check.incomparableCause(x.typ)
+                       cause = check.incomparableCause(x.typ_)
                        goto Error
 
-               case !Comparable(y.typ):
+               case !Comparable(y.typ_):
                        errOp = y
-                       cause = check.incomparableCause(y.typ)
+                       cause = check.incomparableCause(y.typ_)
                        goto Error
                }
 
        case syntax.Lss, syntax.Leq, syntax.Gtr, syntax.Geq:
                // spec: The ordering operators <, <=, >, and >= apply to operands that are ordered."
                switch {
-               case !allOrdered(x.typ):
+               case !allOrdered(x.typ_):
                        errOp = x
                        goto Error
-               case !allOrdered(y.typ):
+               case !allOrdered(y.typ_):
                        errOp = y
                        goto Error
                }
@@ -579,29 +579,29 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase b
                // time will be materialized. Update the expression trees.
                // If the current types are untyped, the materialized type
                // is the respective default type.
-               check.updateExprType(x.expr, Default(x.typ), true)
-               check.updateExprType(y.expr, Default(y.typ), true)
+               check.updateExprType(x.expr, Default(x.typ_), true)
+               check.updateExprType(y.expr, Default(y.typ_), true)
        }
 
        // spec: "Comparison operators compare two operands and yield
        //        an untyped boolean value."
-       x.typ = Typ[UntypedBool]
+       x.typ_ = Typ[UntypedBool]
        return
 
 Error:
        // We have an offending operand errOp and possibly an error cause.
        if cause == "" {
-               if isTypeParam(x.typ) || isTypeParam(y.typ) {
+               if isTypeParam(x.typ_) || isTypeParam(y.typ_) {
                        // TODO(gri) should report the specific type causing the problem, if any
-                       if !isTypeParam(x.typ) {
+                       if !isTypeParam(x.typ_) {
                                errOp = y
                        }
-                       cause = check.sprintf("type parameter %s cannot use operator %s", errOp.typ, op)
+                       cause = check.sprintf("type parameter %s cannot use operator %s", errOp.typ_, op)
                } else {
                        // catch-all: neither x nor y is a type parameter
-                       what := compositeKind(errOp.typ)
+                       what := compositeKind(errOp.typ_)
                        if what == "" {
-                               what = check.sprintf("%s", errOp.typ)
+                               what = check.sprintf("%s", errOp.typ_)
                        }
                        cause = check.sprintf("operator %s not defined on %s", op, what)
                }
@@ -634,7 +634,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                xval = constant.ToInt(x.val)
        }
 
-       if allInteger(x.typ) || isUntyped(x.typ) && xval != nil && xval.Kind() == constant.Int {
+       if allInteger(x.typ_) || isUntyped(x.typ_) && xval != nil && xval.Kind() == constant.Int {
                // The lhs is of integer type or an untyped constant representable
                // as an integer. Nothing to do.
        } else {
@@ -659,7 +659,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                        return
                }
 
-               if isUntyped(y.typ) {
+               if isUntyped(y.typ_) {
                        // 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])
@@ -671,12 +671,12 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
        } else {
                // Check that RHS is otherwise at least of integer type.
                switch {
-               case allInteger(y.typ):
-                       if !allUnsigned(y.typ) && !check.verifyVersionf(y, go1_13, invalidOp+"signed shift count %s", y) {
+               case allInteger(y.typ_):
+                       if !allUnsigned(y.typ_) && !check.verifyVersionf(y, go1_13, invalidOp+"signed shift count %s", y) {
                                x.mode = invalid
                                return
                        }
-               case isUntyped(y.typ):
+               case isUntyped(y.typ_):
                        // This is incorrect, but preserves pre-existing behavior.
                        // See also go.dev/issue/47410.
                        check.convertUntyped(y, Typ[Uint])
@@ -697,8 +697,8 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                        if x.val.Kind() == constant.Unknown || y.val.Kind() == constant.Unknown {
                                x.val = constant.MakeUnknown()
                                // ensure the correct type - see comment below
-                               if !isInteger(x.typ) {
-                                       x.typ = Typ[UntypedInt]
+                               if !isInteger(x.typ_) {
+                                       x.typ_ = Typ[UntypedInt]
                                }
                                return
                        }
@@ -714,8 +714,8 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                        // (e.g., 2.0, an untyped float) - this can only happen for untyped
                        // non-integer numeric constants. Correct the type so that the shift
                        // result is of integer type.
-                       if !isInteger(x.typ) {
-                               x.typ = Typ[UntypedInt]
+                       if !isInteger(x.typ_) {
+                               x.typ_ = Typ[UntypedInt]
                        }
                        // x is a constant so xval != nil and it must be of Int kind.
                        x.val = constant.Shift(xval, op2tok[op], uint(s))
@@ -725,7 +725,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
                }
 
                // non-constant shift with constant lhs
-               if isUntyped(x.typ) {
+               if isUntyped(x.typ_) {
                        // spec: "If the left operand of a non-constant shift
                        // expression is an untyped constant, the type of the
                        // constant is what it would be if the shift expression
@@ -756,7 +756,7 @@ func (check *Checker) shift(x, y *operand, e syntax.Expr, op syntax.Operator) {
        }
 
        // non-constant shift - lhs must be an integer
-       if !allInteger(x.typ) {
+       if !allInteger(x.typ_) {
                check.errorf(x, InvalidShiftOperand, invalidOp+"shifted operand %s must be integer", x)
                x.mode = invalid
                return
@@ -818,14 +818,14 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
                return
        }
 
-       if !Identical(x.typ, y.typ) {
+       if !Identical(x.typ_, y.typ_) {
                // only report an error if we have valid types
                // (otherwise we had an error reported elsewhere already)
-               if isValid(x.typ) && isValid(y.typ) {
+               if isValid(x.typ_) && isValid(y.typ_) {
                        if e != nil {
-                               check.errorf(x, MismatchedTypes, invalidOp+"%s (mismatched types %s and %s)", e, x.typ, y.typ)
+                               check.errorf(x, MismatchedTypes, invalidOp+"%s (mismatched types %s and %s)", e, x.typ_, y.typ_)
                        } else {
-                               check.errorf(x, MismatchedTypes, invalidOp+"%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ, y.typ)
+                               check.errorf(x, MismatchedTypes, invalidOp+"%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ_, y.typ_)
                        }
                }
                x.mode = invalid
@@ -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 {
@@ -866,7 +866,7 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
                }
                // force integer division for integer operands
                tok := op2tok[op]
-               if op == syntax.Div && isInteger(x.typ) {
+               if op == syntax.Div && isInteger(x.typ_) {
                        tok = token.QUO_ASSIGN
                }
                x.val = constant.BinaryOp(x.val, tok, y.val)
@@ -893,49 +893,49 @@ func (check *Checker) matchTypes(x, y *operand) {
        // not compatible, we report a type mismatch error.
        mayConvert := func(x, y *operand) bool {
                // If both operands are typed, there's no need for an implicit conversion.
-               if isTyped(x.typ) && isTyped(y.typ) {
+               if isTyped(x.typ_) && isTyped(y.typ_) {
                        return false
                }
                // A numeric type can only convert to another numeric type.
-               if allNumeric(x.typ) != allNumeric(y.typ) {
+               if allNumeric(x.typ_) != allNumeric(y.typ_) {
                        return false
                }
                // An untyped operand may convert to its default type when paired with an empty interface
                // TODO(gri) This should only matter for comparisons (the only binary operation that is
                //           valid with interfaces), but in that case the assignability check should take
                //           care of the conversion. Verify and possibly eliminate this extra test.
-               if isNonTypeParamInterface(x.typ) || isNonTypeParamInterface(y.typ) {
+               if isNonTypeParamInterface(x.typ_) || isNonTypeParamInterface(y.typ_) {
                        return true
                }
                // A boolean type can only convert to another boolean type.
-               if allBoolean(x.typ) != allBoolean(y.typ) {
+               if allBoolean(x.typ_) != allBoolean(y.typ_) {
                        return false
                }
                // A string type can only convert to another string type.
-               if allString(x.typ) != allString(y.typ) {
+               if allString(x.typ_) != allString(y.typ_) {
                        return false
                }
                // Untyped nil can only convert to a type that has a nil.
                if x.isNil() {
-                       return hasNil(y.typ)
+                       return hasNil(y.typ_)
                }
                if y.isNil() {
-                       return hasNil(x.typ)
+                       return hasNil(x.typ_)
                }
                // An untyped operand cannot convert to a pointer.
                // TODO(gri) generalize to type parameters
-               if isPointer(x.typ) || isPointer(y.typ) {
+               if isPointer(x.typ_) || isPointer(y.typ_) {
                        return false
                }
                return true
        }
 
        if mayConvert(x, y) {
-               check.convertUntyped(x, y.typ)
+               check.convertUntyped(x, y.typ_)
                if x.mode == invalid {
                        return
                }
-               check.convertUntyped(y, x.typ)
+               check.convertUntyped(y, x.typ_)
                if y.mode == invalid {
                        x.mode = invalid
                        return
@@ -1007,7 +1007,7 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
                return
        }
        var what string
-       switch t := x.typ.(type) {
+       switch t := x.typ_.(type) {
        case *Alias, *Named:
                if isGeneric(t) {
                        what = "type"
@@ -1024,7 +1024,7 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
        if what != "" {
                check.errorf(x.expr, WrongTypeArgCount, "cannot use generic %s %s without instantiation", what, x.expr)
                x.mode = invalid
-               x.typ = Typ[Invalid]
+               x.typ_ = Typ[Invalid]
        }
 }
 
@@ -1035,7 +1035,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
        // make sure x has a valid state in case of bailout
        // (was go.dev/issue/5770)
        x.mode = invalid
-       x.typ = Typ[Invalid]
+       x.typ_ = Typ[Invalid]
 
        switch e := e.(type) {
        case nil:
@@ -1109,11 +1109,11 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                        check.error(e, InvalidSyntaxTree, "invalid use of AssertExpr")
                        goto Error
                }
-               if isTypeParam(x.typ) {
+               if isTypeParam(x.typ_) {
                        check.errorf(x, InvalidAssert, invalidOp+"cannot use type assertion on type parameter value %s", x)
                        goto Error
                }
-               if _, ok := x.typ.Underlying().(*Interface); !ok {
+               if _, ok := x.typ_.Underlying().(*Interface); !ok {
                        check.errorf(x, InvalidAssert, invalidOp+"%s is not an interface", x)
                        goto Error
                }
@@ -1127,7 +1127,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                }
                check.typeAssertion(e, x, T, false)
                x.mode = commaok
-               x.typ = T
+               x.typ_ = T
 
        case *syntax.TypeSwitchGuard:
                // x.(type) expressions are handled explicitly in type switches
@@ -1173,11 +1173,11 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                                case invalid:
                                        goto Error
                                case typexpr:
-                                       check.validVarType(e.X, x.typ)
-                                       x.typ = &Pointer{base: x.typ}
+                                       check.validVarType(e.X, x.typ_)
+                                       x.typ_ = &Pointer{base: x.typ_}
                                default:
                                        var base Type
-                                       if !underIs(x.typ, func(u Type) bool {
+                                       if !underIs(x.typ_, func(u Type) bool {
                                                p, _ := u.(*Pointer)
                                                if p == nil {
                                                        check.errorf(x, InvalidIndirection, invalidOp+"cannot indirect %s", x)
@@ -1197,7 +1197,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
                                                goto Error
                                        }
                                        x.mode = variable
-                                       x.typ = base
+                                       x.typ_ = base
                                }
                                break
                        }
@@ -1227,7 +1227,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
        case *syntax.ArrayType, *syntax.SliceType, *syntax.StructType, *syntax.FuncType,
                *syntax.InterfaceType, *syntax.MapType, *syntax.ChanType:
                x.mode = typexpr
-               x.typ = check.typ(e)
+               x.typ_ = check.typ(e)
                // Note: rawExpr (caller of exprInternal) will call check.recordTypeAndValue
                // even though check.typ has already called it. This is fine as both
                // times the same expression and type are recorded. It is also not a
@@ -1293,7 +1293,7 @@ func keyVal(x constant.Value) any {
 // typeAssertion checks x.(T). The type of x must be an interface.
 func (check *Checker) typeAssertion(e syntax.Expr, x *operand, T Type, typeSwitch bool) {
        var cause string
-       if check.assertableTo(x.typ, T, &cause) {
+       if check.assertableTo(x.typ_, T, &cause) {
                return // success
        }
 
@@ -1302,7 +1302,7 @@ func (check *Checker) typeAssertion(e syntax.Expr, x *operand, T Type, typeSwitc
                return
        }
 
-       check.errorf(e, ImpossibleAssert, "impossible type assertion: %s\n\t%s does not implement %s %s", e, T, x.typ, cause)
+       check.errorf(e, ImpossibleAssert, "impossible type assertion: %s\n\t%s does not implement %s %s", e, T, x.typ_, cause)
 }
 
 // expr typechecks expression e and initializes x with the expression value.
@@ -1333,11 +1333,11 @@ 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 {
-                       list[i] = &operand{mode: value, expr: e, typ: v.typ}
+                       list[i] = &operand{mode: value, expr: e, typ_: v.typ}
                }
                return
        }
@@ -1345,9 +1345,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) {
-               x2 := &operand{mode: value, expr: e, typ: Typ[UntypedBool]}
+               x2 := &operand{mode: value, expr: e, typ_: Typ[UntypedBool]}
                if x.mode == commaerr {
-                       x2.typ = universeError
+                       x2.typ_ = universeError
                }
                list = append(list, x2)
                commaOk = true
@@ -1408,7 +1408,7 @@ func (check *Checker) exclude(x *operand, modeset uint) {
 func (check *Checker) singleValue(x *operand) {
        if x.mode == value {
                // tuple types are never named - no need for underlying type below
-               if t, ok := x.typ.(*Tuple); ok {
+               if t, ok := x.typ_.(*Tuple); ok {
                        assert(t.Len() != 1)
                        check.errorf(x, TooManyValues, "multiple-value %s in single-value context", x)
                        x.mode = invalid
index 5b52cea83774db3127ba7602c16a781b05d6f1e5..6c659a599d77cee85b14c4c0c454f7a8359e2754 100644 (file)
@@ -28,14 +28,14 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                // type instantiation
                x.mode = invalid
                // TODO(gri) here we re-evaluate e.X - try to avoid this
-               x.typ = check.varType(e)
-               if isValid(x.typ) {
+               x.typ_ = check.varType(e)
+               if isValid(x.typ_) {
                        x.mode = typexpr
                }
                return false
 
        case value:
-               if sig, _ := x.typ.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
+               if sig, _ := x.typ_.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
                        // function instantiation
                        return true
                }
@@ -48,11 +48,11 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
        }
 
        // We cannot index on an incomplete type; make sure it's complete.
-       if !check.isComplete(x.typ) {
+       if !check.isComplete(x.typ_) {
                x.mode = invalid
                return false
        }
-       switch typ := x.typ.Underlying().(type) {
+       switch typ := x.typ_.Underlying().(type) {
        case *Pointer:
                // Additionally, if x.typ is a pointer to an array type, indexing implicitly dereferences the value, meaning
                // its base type must also be complete.
@@ -72,7 +72,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
        // ordinary index expression
        valid := false
        length := int64(-1) // valid if >= 0
-       switch typ := x.typ.Underlying().(type) {
+       switch typ := x.typ_.Underlying().(type) {
        case *Basic:
                if isString(typ) {
                        valid = true
@@ -83,7 +83,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                        // (not a constant) even if the string and the
                        // index are constant
                        x.mode = value
-                       x.typ = universeByte // use 'byte' name
+                       x.typ_ = universeByte // use 'byte' name
                }
 
        case *Array:
@@ -92,20 +92,20 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                if x.mode != variable {
                        x.mode = value
                }
-               x.typ = typ.elem
+               x.typ_ = typ.elem
 
        case *Pointer:
                if typ, _ := typ.base.Underlying().(*Array); typ != nil {
                        valid = true
                        length = typ.len
                        x.mode = variable
-                       x.typ = typ.elem
+                       x.typ_ = typ.elem
                }
 
        case *Slice:
                valid = true
                x.mode = variable
-               x.typ = typ.elem
+               x.typ_ = typ.elem
 
        case *Map:
                index := check.singleIndex(e)
@@ -118,19 +118,19 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                check.assignment(&key, typ.key, "map index")
                // ok to continue even if indexing failed - map element type is known
                x.mode = mapindex
-               x.typ = typ.elem
+               x.typ_ = typ.elem
                x.expr = e
                return false
 
        case *Interface:
-               if !isTypeParam(x.typ) {
+               if !isTypeParam(x.typ_) {
                        break
                }
                // TODO(gri) report detailed failure cause for better error messages
                var key, elem Type // key != nil: we must have all maps
                mode := variable   // non-maps result mode
                // TODO(gri) factor out closure and use it for non-typeparam cases as well
-               if underIs(x.typ, func(u Type) bool {
+               if underIs(x.typ_, func(u Type) bool {
                        l := int64(-1) // valid if >= 0
                        var k, e Type  // k is only set for maps
                        switch t := u.(type) {
@@ -192,7 +192,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                                check.assignment(&k, key, "map index")
                                // ok to continue even if indexing failed - map element type is known
                                x.mode = mapindex
-                               x.typ = elem
+                               x.typ_ = elem
                                x.expr = e
                                return false
                        }
@@ -200,7 +200,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
                        // no maps
                        valid = true
                        x.mode = mode
-                       x.typ = elem
+                       x.typ_ = elem
                }
        }
 
@@ -220,8 +220,8 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
        // In pathological (invalid) cases (e.g.: type T1 [][[]T1{}[0][0]]T0)
        // the element type may be accessed before it's set. Make sure we have
        // a valid type.
-       if x.typ == nil {
-               x.typ = Typ[Invalid]
+       if x.typ_ == nil {
+               x.typ_ = Typ[Invalid]
        }
 
        check.index(index, length)
@@ -238,9 +238,9 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
        // determine common underlying type cu
        var ct, cu Type // type and respective common underlying type
        var hasString bool
-       for t, u := range typeset(x.typ) {
+       for t, u := range typeset(x.typ_) {
                if u == nil {
-                       check.errorf(x, NonSliceableOperand, "cannot slice %s: no specific type in %s", x, x.typ)
+                       check.errorf(x, NonSliceableOperand, "cannot slice %s: no specific type in %s", x, x.typ_)
                        cu = nil
                        break
                }
@@ -268,15 +268,15 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
                // If we saw a string, proceed with string type,
                // but don't go from untyped string to string.
                cu = Typ[String]
-               if !isTypeParam(x.typ) {
-                       cu = x.typ.Underlying() // untyped string remains untyped
+               if !isTypeParam(x.typ_) {
+                       cu = x.typ_.Underlying() // untyped string remains untyped
                }
        }
 
        // Note that we don't permit slice expressions where x is a type expression, so we don't check for that here.
        // However, if x.typ is a pointer to an array type, slicing implicitly dereferences the value, meaning
        // its base type must also be complete.
-       if p, ok := x.typ.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
+       if p, ok := x.typ_.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
                x.mode = invalid
                return
        }
@@ -306,8 +306,8 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
                        }
                        // spec: "For untyped string operands the result
                        // is a non-constant value of type string."
-                       if isUntyped(x.typ) {
-                               x.typ = Typ[String]
+                       if isUntyped(x.typ_) {
+                               x.typ_ = Typ[String]
                        }
                }
 
@@ -319,13 +319,13 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) {
                        x.mode = invalid
                        return
                }
-               x.typ = &Slice{elem: u.elem}
+               x.typ_ = &Slice{elem: u.elem}
 
        case *Pointer:
                if u, _ := u.base.Underlying().(*Array); u != nil {
                        valid = true
                        length = u.len
-                       x.typ = &Slice{elem: u.elem}
+                       x.typ_ = &Slice{elem: u.elem}
                }
 
        case *Slice:
@@ -428,7 +428,7 @@ func (check *Checker) index(index syntax.Expr, max int64) (typ Type, val int64)
        }
 
        if x.mode != constant_ {
-               return x.typ, -1
+               return x.typ_, -1
        }
 
        if x.val.Kind() == constant.Unknown {
@@ -443,7 +443,7 @@ func (check *Checker) index(index syntax.Expr, max int64) (typ Type, val int64)
        }
 
        // 0 <= v [ && v < max ]
-       return x.typ, v
+       return x.typ_, v
 }
 
 // isValidIndex checks whether operand x satisfies the criteria for integer
@@ -462,7 +462,7 @@ func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNega
        }
 
        // spec: "the index x must be of integer type or an untyped constant"
-       if !allInteger(x.typ) {
+       if !allInteger(x.typ_) {
                check.errorf(x, code, invalidArg+"%s %s must be integer", what, x)
                return false
        }
index 996f6a510905850dd3fe09799bb7d110a0586728..5ba3583916368d34da6737fb2f923634e5dc2a6e 100644 (file)
@@ -170,12 +170,12 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
                        continue
                }
                par := params.At(i)
-               if isParameterized(tparams, par.typ) || isParameterized(tparams, arg.typ) {
+               if isParameterized(tparams, par.typ) || isParameterized(tparams, arg.typ_) {
                        // Function parameters are always typed. Arguments may be untyped.
                        // Collect the indices of untyped arguments and handle them later.
-                       if isTyped(arg.typ) {
-                               if !u.unify(par.typ, arg.typ, assign) {
-                                       errorf(par.typ, arg.typ, arg)
+                       if isTyped(arg.typ_) {
+                               if !u.unify(par.typ, arg.typ_, assign) {
+                                       errorf(par.typ, arg.typ_, arg)
                                        return nil
                                }
                        } else if _, ok := par.typ.(*TypeParam); ok && !arg.isNil() {
@@ -337,11 +337,11 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
                        }
                        max := maxUntyped[tpar]
                        if max == nil {
-                               max = arg.typ
+                               max = arg.typ_
                        } else {
-                               m := maxType(max, arg.typ)
+                               m := maxType(max, arg.typ_)
                                if m == nil {
-                                       err.addf(arg, "mismatched types %s and %s (cannot infer %s)", max, arg.typ, tpar)
+                                       err.addf(arg, "mismatched types %s and %s (cannot infer %s)", max, arg.typ_, tpar)
                                        return nil
                                }
                                max = m
index 6817231a763dcf139bc11c382e8539f04d0b4b31..893f37caa50bf324e50a8765a81147ffa870ef15 100644 (file)
@@ -97,7 +97,7 @@ func (check *Checker) funcLit(x *operand, e *syntax.FuncLit) {
                        }).describef(e, "func literal")
                }
                x.mode = value
-               x.typ = sig
+               x.typ_ = sig
        } else {
                check.errorf(e, InvalidSyntaxTree, "invalid function literal %v", e)
                x.mode = invalid
@@ -269,12 +269,12 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
                                xkey := keyVal(x.val)
                                if keyIsInterface {
                                        for _, vtyp := range visited[xkey] {
-                                               if Identical(vtyp, x.typ) {
+                                               if Identical(vtyp, x.typ_) {
                                                        duplicate = true
                                                        break
                                                }
                                        }
-                                       visited[xkey] = append(visited[xkey], x.typ)
+                                       visited[xkey] = append(visited[xkey], x.typ_)
                                } else {
                                        _, duplicate = visited[xkey]
                                        visited[xkey] = nil
@@ -317,7 +317,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
        }
 
        x.mode = value
-       x.typ = typ
+       x.typ_ = typ
 }
 
 // indexedElts checks the elements (elts) of an array or slice composite literal
index cd9e9f3575f71a655aa38b98346f27e1f950ec04..884b4edb81ce3990d0fa4aaf8ff4adf8f85e4eee 100644 (file)
@@ -55,7 +55,7 @@ var operandModeString = [...]string{
 type operand struct {
        mode operandMode
        expr syntax.Expr
-       typ  Type
+       typ_ Type
        val  constant.Value
        id   builtinId
 }
@@ -110,17 +110,17 @@ func operandString(x *operand, qf Qualifier) string {
        // special-case nil
        if isTypes2 {
                if x.mode == nilvalue {
-                       switch x.typ {
+                       switch x.typ_ {
                        case nil, Typ[Invalid]:
                                return "nil (with invalid type)"
                        case Typ[UntypedNil]:
                                return "nil"
                        default:
-                               return fmt.Sprintf("nil (of type %s)", TypeString(x.typ, qf))
+                               return fmt.Sprintf("nil (of type %s)", TypeString(x.typ_, qf))
                        }
                }
        } else { // go/types
-               if x.mode == value && x.typ == Typ[UntypedNil] {
+               if x.mode == value && x.typ_ == Typ[UntypedNil] {
                        return "nil"
                }
        }
@@ -135,7 +135,7 @@ func operandString(x *operand, qf Qualifier) string {
                case builtin:
                        expr = predeclaredFuncs[x.id].name
                case typexpr:
-                       expr = TypeString(x.typ, qf)
+                       expr = TypeString(x.typ_, qf)
                case constant_:
                        expr = x.val.String()
                }
@@ -154,9 +154,9 @@ func operandString(x *operand, qf Qualifier) string {
                // no type
        default:
                // should have a type, but be cautious (don't crash during printing)
-               if x.typ != nil {
-                       if isUntyped(x.typ) {
-                               buf.WriteString(x.typ.(*Basic).name)
+               if x.typ_ != nil {
+                       if isUntyped(x.typ_) {
+                               buf.WriteString(x.typ_.(*Basic).name)
                                buf.WriteByte(' ')
                                break
                        }
@@ -177,9 +177,9 @@ func operandString(x *operand, qf Qualifier) string {
 
        // <typ>
        if hasType {
-               if isValid(x.typ) {
+               if isValid(x.typ_) {
                        var desc string
-                       if isGeneric(x.typ) {
+                       if isGeneric(x.typ_) {
                                desc = "generic "
                        }
 
@@ -187,14 +187,14 @@ func operandString(x *operand, qf Qualifier) string {
                        // If the type is a renamed basic type, describe the basic type,
                        // as in "int32 type MyInt" for a *Named type MyInt.
                        // If it is a type parameter, describe the constraint instead.
-                       tpar, _ := Unalias(x.typ).(*TypeParam)
+                       tpar, _ := Unalias(x.typ_).(*TypeParam)
                        if tpar == nil {
-                               switch x.typ.(type) {
+                               switch x.typ_.(type) {
                                case *Alias, *Named:
-                                       what := compositeKind(x.typ)
+                                       what := compositeKind(x.typ_)
                                        if what == "" {
                                                // x.typ must be basic type
-                                               what = x.typ.Underlying().(*Basic).name
+                                               what = x.typ_.Underlying().(*Basic).name
                                        }
                                        desc += what + " "
                                }
@@ -202,7 +202,7 @@ func operandString(x *operand, qf Qualifier) string {
                        // desc is "" or has a trailing space at the end
 
                        buf.WriteString(" of " + desc + "type ")
-                       WriteType(&buf, x.typ, qf)
+                       WriteType(&buf, x.typ_, qf)
 
                        if tpar != nil {
                                buf.WriteString(" constrained by ")
@@ -282,11 +282,11 @@ func (x *operand) setConst(k syntax.LitKind, lit string) {
        val := makeFromLiteral(lit, k)
        if val.Kind() == constant.Unknown {
                x.mode = invalid
-               x.typ = Typ[Invalid]
+               x.typ_ = Typ[Invalid]
                return
        }
        x.mode = constant_
-       x.typ = Typ[kind]
+       x.typ_ = Typ[kind]
        x.val = val
 }
 
@@ -295,7 +295,7 @@ func (x *operand) isNil() bool {
        if isTypes2 {
                return x.mode == nilvalue
        } else { // go/types
-               return x.mode == value && x.typ == Typ[UntypedNil]
+               return x.mode == value && x.typ_ == Typ[UntypedNil]
        }
 }
 
@@ -311,7 +311,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
        }
 
        origT := T
-       V := Unalias(x.typ)
+       V := Unalias(x.typ_)
        T = Unalias(T)
 
        // x's type is identical to T
@@ -416,7 +416,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
                        }
                        ok, code = x.assignableTo(check, T.typ, cause)
                        if !ok {
-                               errorf("cannot assign %s to %s (in %s)", x.typ, T.typ, Tp)
+                               errorf("cannot assign %s to %s (in %s)", x.typ_, T.typ, Tp)
                                return false
                        }
                        return true
@@ -435,7 +435,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
                        if V == nil {
                                return false // no specific types
                        }
-                       x.typ = V.typ
+                       x.typ_ = V.typ
                        ok, code = x.assignableTo(check, T, cause)
                        if !ok {
                                errorf("cannot assign %s (in %s) to %s", V.typ, Vp, origT)
index 899f5c09911a5e0b3f549ac1c62cc484584e2a03..37a701a0fb0e16818e001f017bb3d506d84c4c36 100644 (file)
@@ -35,7 +35,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
        check.expr(nil, &x, rangeVar)
 
        if isTypes2 && x.mode != invalid && sValue == nil && !check.hasCallOrRecv {
-               if t, ok := arrayPtrDeref(x.typ.Underlying()).(*Array); ok {
+               if t, ok := arrayPtrDeref(x.typ_.Underlying()).(*Array); ok {
                        for {
                                // Put constant info on the thing inside parentheses.
                                // That's where (*../noder/writer).expr expects it.
@@ -52,7 +52,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
                        check.record(&operand{
                                mode: constant_,
                                expr: rangeVar,
-                               typ Typ[Int],
+                               typ_: Typ[Int],
                                val:  constant.MakeInt64(t.len),
                                id:   x.id,
                        })
@@ -62,7 +62,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
        // determine key/value types
        var key, val Type
        if x.mode != invalid {
-               k, v, cause, ok := rangeKeyVal(check, x.typ, func(v goVersion) bool {
+               k, v, cause, ok := rangeKeyVal(check, x.typ_, func(v goVersion) bool {
                        return check.allowVersion(v)
                })
                switch {
@@ -92,7 +92,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
        lhs := [2]syntax.Expr{sKey, sValue} // sKey, sValue may be nil
        rhs := [2]Type{key, val}            // key, val may be nil
 
-       rangeOverInt := isInteger(x.typ)
+       rangeOverInt := isInteger(x.typ_)
 
        if isDef {
                // short variable declaration
@@ -135,7 +135,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
                                var y operand
                                y.mode = value
                                y.expr = lhs // we don't have a better rhs expression to use here
-                               y.typ = typ
+                               y.typ_ = typ
                                check.initVar(obj, &y, "assignment") // error is on variable, use "assignment" not "range clause"
                        }
                        assert(obj.typ != nil)
@@ -169,14 +169,14 @@ 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) {
-                                       check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ)
+                               if x.mode != invalid && !isInteger(x.typ_) {
+                                       check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ_)
                                }
                        } else {
                                var y operand
                                y.mode = value
                                y.expr = lhs // we don't have a better rhs expression to use here
-                               y.typ = typ
+                               y.typ_ = typ
                                check.assignVar(lhs, nil, &y, "assignment") // error is on variable, use "assignment" not "range clause"
                        }
                }
index 2c83dd2db9df13634a86304c67f3c5b3c7fae237..5a6b295418bf2e44444a4f825f84434aee78cdc8 100644 (file)
@@ -23,10 +23,10 @@ func (check *Checker) record(x *operand) {
        case novalue:
                typ = (*Tuple)(nil)
        case constant_:
-               typ = x.typ
+               typ = x.typ_
                val = x.val
        default:
-               typ = x.typ
+               typ = x.typ_
        }
        assert(x.expr != nil && typ != nil)
 
@@ -97,7 +97,7 @@ func (check *Checker) recordCommaOkTypes(x syntax.Expr, a []*operand) {
        if a[0].mode == invalid {
                return
        }
-       t0, t1 := a[0].typ, a[1].typ
+       t0, t1 := a[0].typ_, a[1].typ_
        assert(isTyped(t0) && isTyped(t1) && (allBoolean(t1) || t1 == universeError))
        if m := check.Types; m != nil {
                for {
index 47ca4d90ec7a3b3996d6a1ece3d9ecc4b04ce7ee..732f8a9b7440a3f4ec881298fb248d8fd5a7d6e4 100644 (file)
@@ -241,7 +241,7 @@ L:
                if x.mode == invalid || v.mode == invalid {
                        continue L
                }
-               check.convertUntyped(&v, x.typ)
+               check.convertUntyped(&v, x.typ_)
                if v.mode == invalid {
                        continue L
                }
@@ -259,7 +259,7 @@ L:
                        // look for duplicate types for a given value
                        // (quadratic algorithm, but these lists tend to be very short)
                        for _, vt := range seen[val] {
-                               if Identical(v.typ, vt.typ) {
+                               if Identical(v.typ_, vt.typ) {
                                        err := check.newError(DuplicateCase)
                                        err.addf(&v, "duplicate case %s in expression switch", &v)
                                        err.addf(vt.pos, "previous case")
@@ -267,7 +267,7 @@ L:
                                        continue L
                                }
                        }
-                       seen[val] = append(seen[val], valueType{v.Pos(), v.typ})
+                       seen[val] = append(seen[val], valueType{v.Pos(), v.typ_})
                }
        }
 }
@@ -345,7 +345,7 @@ L:
        if len(types) != 1 || T == nil {
                T = Typ[Invalid]
                if x != nil {
-                       T = x.typ
+                       T = x.typ_
                }
        }
 
@@ -398,7 +398,7 @@ L:
        if len(types) != 1 || T == nil {
                T = Typ[Invalid]
                if x != nil {
-                       T = x.typ
+                       T = x.typ_
                }
        }
 
@@ -480,8 +480,8 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
                        if x.mode == invalid {
                                return
                        }
-                       if !allNumeric(x.typ) {
-                               check.errorf(s.Lhs, NonNumericIncDec, invalidOp+"%s%s%s (non-numeric type %s)", s.Lhs, s.Op, s.Op, x.typ)
+                       if !allNumeric(x.typ_) {
+                               check.errorf(s.Lhs, NonNumericIncDec, invalidOp+"%s%s%s (non-numeric type %s)", s.Lhs, s.Op, s.Op, x.typ_)
                                return
                        }
                        check.assignVar(s.Lhs, nil, &x, "assignment")
@@ -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,15 +721,15 @@ 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) {
-                       check.errorf(&x, InvalidExprSwitch, "cannot switch on %s (%s is not comparable)", &x, 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
                }
        } else {
                // spec: "A missing switch expression is
                // equivalent to the boolean value true."
                x.mode = constant_
-               x.typ = Typ[Bool]
+               x.typ_ = Typ[Bool]
                x.val = constant.MakeBool(true)
                // TODO(gri) should have a better position here
                pos := s.Rbrace
@@ -786,9 +786,9 @@ func (check *Checker) typeSwitchStmt(inner stmtContext, s *syntax.SwitchStmt, gu
                var x operand
                check.expr(nil, &x, guard.X)
                if x.mode != invalid {
-                       if isTypeParam(x.typ) {
+                       if isTypeParam(x.typ_) {
                                check.errorf(&x, InvalidTypeSwitch, "cannot use type switch on type parameter value %s", &x)
-                       } else if IsInterface(x.typ) {
+                       } else if IsInterface(x.typ_) {
                                sx = &x
                        } else {
                                check.errorf(&x, InvalidTypeSwitch, "%s is not an interface", &x)
index ac81b838dea4902e6c404ede3036c6f56dd9fc5e..49f4dbc249143ddaec79e3f8d3a9b67230f1e9ce 100644 (file)
@@ -132,7 +132,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, wantType bool) {
                panic("unreachable")
        }
 
-       x.typ = typ
+       x.typ_ = typ
 }
 
 // typ type-checks the type expression e and returns its type, or Typ[Invalid].
@@ -250,7 +250,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *TypeName) (T Type) {
 
                switch x.mode {
                case typexpr:
-                       return x.typ
+                       return x.typ_
                case invalid:
                        // ignore - error reported before
                case novalue:
@@ -265,7 +265,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *TypeName) (T Type) {
 
                switch x.mode {
                case typexpr:
-                       return x.typ
+                       return x.typ_
                case invalid:
                        // ignore - error reported before
                case novalue:
@@ -489,7 +489,7 @@ func (check *Checker) arrayLength(e syntax.Expr) int64 {
                return -1
        }
 
-       if isUntyped(x.typ) || isInteger(x.typ) {
+       if isUntyped(x.typ_) || isInteger(x.typ_) {
                if val := constant.ToInt(x.val); val.Kind() == constant.Int {
                        if representableConst(val, check, Typ[Int], nil) {
                                if n, ok := constant.Int64Val(val); ok && n >= 0 {
@@ -500,7 +500,7 @@ func (check *Checker) arrayLength(e syntax.Expr) int64 {
        }
 
        var msg string
-       if isInteger(x.typ) {
+       if isInteger(x.typ_) {
                msg = "invalid array length %s"
        } else {
                msg = "array length %s must be integer"
index d0c9788b9da7b0e714240a3185cfb8e692af0121..d2cc382f2f772725a5f59ebef96f7abf29019900 100644 (file)
@@ -31,7 +31,7 @@ func AssertableTo(V *Interface, T Type) bool {
 // The behavior of AssignableTo is unspecified if V or T is Typ[Invalid] or an
 // uninstantiated generic type.
 func AssignableTo(V, T Type) bool {
-       x := operand{mode: value, typ: V}
+       x := operand{mode: value, typ_: V}
        ok, _ := x.assignableTo(nil, T, nil) // check not needed for non-constant x
        return ok
 }
@@ -42,7 +42,7 @@ func AssignableTo(V, T Type) bool {
 // The behavior of ConvertibleTo is unspecified if V or T is Typ[Invalid] or an
 // uninstantiated generic type.
 func ConvertibleTo(V, T Type) bool {
-       x := operand{mode: value, typ: V}
+       x := operand{mode: value, typ_: V}
        return x.convertibleTo(nil, T, nil) // check not needed for non-constant x
 }
 
index 1524451af766ffb62240b73a228374cc73f73d92..0cacadb759899704c5d06022c5ecd7bee0e1f053 100644 (file)
@@ -40,7 +40,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                return
        }
 
-       if isUntyped(x.typ) {
+       if isUntyped(x.typ_) {
                target := T
                // spec: "If an untyped constant is assigned to a variable of interface
                // type or the blank identifier, the constant is first converted to type
@@ -55,16 +55,16 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                                        return
                                }
                        } else if T == nil || isNonTypeParamInterface(T) {
-                               target = Default(x.typ)
+                               target = Default(x.typ_)
                        }
                } else { // go/types
                        if T == nil || isNonTypeParamInterface(T) {
-                               if T == nil && x.typ == Typ[UntypedNil] {
+                               if T == nil && x.typ_ == Typ[UntypedNil] {
                                        check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
                                        x.mode = invalid
                                        return
                                }
-                               target = Default(x.typ)
+                               target = Default(x.typ_)
                        }
                }
                newType, val, code := check.implicitTypeAndValue(x, target)
@@ -86,15 +86,15 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                        x.val = val
                        check.updateExprVal(x.expr, val)
                }
-               if newType != x.typ {
-                       x.typ = newType
+               if newType != x.typ_ {
+                       x.typ_ = newType
                        check.updateExprType(x.expr, newType, false)
                }
        }
        // x.typ is typed
 
        // A generic (non-instantiated) function value cannot be assigned to a variable.
-       if sig, _ := x.typ.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
+       if sig, _ := x.typ_.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
                check.errorf(x, WrongTypeArgCount, "cannot use generic function %s without instantiation in %s", x, context)
                x.mode = invalid
                return
@@ -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]
                }
@@ -134,11 +134,11 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
                }
                return
        }
-       assert(isConstType(x.typ))
+       assert(isConstType(x.typ_))
 
        // If the lhs doesn't have a type yet, use the type of x.
        if lhs.typ == nil {
-               lhs.typ = x.typ
+               lhs.typ = x.typ_
        }
 
        check.assignment(x, lhs.typ, "constant declaration")
@@ -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]
                }
@@ -164,7 +164,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) {
 
        // If lhs doesn't have a type yet, use the type of x.
        if lhs.typ == nil {
-               typ := x.typ
+               typ := x.typ_
                if isUntyped(typ) {
                        // convert untyped types to default types
                        if typ == Typ[UntypedNil] {
@@ -219,7 +219,7 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type {
                check.usedVars[v] = v_used // restore v.used
        }
 
-       if x.mode == invalid || !isValid(x.typ) {
+       if x.mode == invalid || !isValid(x.typ_) {
                return Typ[Invalid]
        }
 
@@ -243,7 +243,7 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type {
                return Typ[Invalid]
        }
 
-       return x.typ
+       return x.typ_
 }
 
 // assignVar checks the assignment lhs = rhs (if x == nil), or lhs = x (if x != nil).
@@ -281,7 +281,7 @@ func (check *Checker) assignVar(lhs, rhs ast.Expr, x *operand, context string) {
 // operandTypes returns the list of types for the given operands.
 func operandTypes(list []*operand) (res []Type) {
        for _, x := range list {
-               res = append(res, x.typ)
+               res = append(res, x.typ_)
        }
        return res
 }
index 3b8a91a9f7a43b043450179804b01fcdf1a42910..bb65981b55a80a7744dca5176d3db558ca0bc4a9 100644 (file)
@@ -112,7 +112,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
                                y := args[1]
                                hasString := false
-                               for _, u := range typeset(y.typ) {
+                               for _, u := range typeset(y.typ_) {
                                        if s, _ := u.(*Slice); s != nil && Identical(s.elem, universeByte) {
                                                // typeset ⊇ {[]byte}
                                        } else if isString(u) {
@@ -125,7 +125,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                }
                                if y != nil && hasString {
                                        // setting the signature also signals that we're done
-                                       sig = makeSig(x.typ, x.typ, y.typ)
+                                       sig = makeSig(x.typ_, x.typ_, y.typ_)
                                        sig.variadic = true
                                }
                        }
@@ -134,7 +134,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // general case
                if sig == nil {
                        // check arguments by creating custom signature
-                       sig = makeSig(x.typ, x.typ, NewSlice(E)) // []E required for variadic signature
+                       sig = makeSig(x.typ_, x.typ_, NewSlice(E)) // []E required for variadic signature
                        sig.variadic = true
                        check.arguments(call, sig, nil, nil, args, nil) // discard result (we know the result type)
                        // ok to continue even if check.arguments reported errors
@@ -151,7 +151,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // len(x)
                mode := invalid
                var val constant.Value
-               switch t := arrayPtrDeref(x.typ.Underlying()).(type) {
+               switch t := arrayPtrDeref(x.typ_.Underlying()).(type) {
                case *Basic:
                        if isString(t) && id == _Len {
                                if x.mode == constant_ {
@@ -186,10 +186,10 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        }
 
                case *Interface:
-                       if !isTypeParam(x.typ) {
+                       if !isTypeParam(x.typ_) {
                                break
                        }
-                       if underIs(x.typ, func(u Type) bool {
+                       if underIs(x.typ_, func(u Type) bool {
                                switch t := arrayPtrDeref(u).(type) {
                                case *Basic:
                                        if isString(t) && id == _Len {
@@ -210,7 +210,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
                if mode == invalid {
                        // avoid error if underlying type is invalid
-                       if isValid(x.typ.Underlying()) {
+                       if isValid(x.typ_.Underlying()) {
                                code := InvalidCap
                                if id == _Len {
                                        code = InvalidLen
@@ -222,18 +222,18 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
                // record the signature before changing x.typ
                if check.recordTypes() && mode != constant_ {
-                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ_))
                }
 
                x.mode = mode
-               x.typ = Typ[Int]
+               x.typ_ = Typ[Int]
                x.val = val
 
        case _Clear:
                // clear(m)
                check.verifyVersionf(call.Fun, go1_21, "clear")
 
-               if !underIs(x.typ, func(u Type) bool {
+               if !underIs(x.typ_, func(u Type) bool {
                        switch u.(type) {
                        case *Map, *Slice:
                                return true
@@ -246,12 +246,12 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
                x.mode = novalue
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ_))
                }
 
        case _Close:
                // close(c)
-               if !underIs(x.typ, func(u Type) bool {
+               if !underIs(x.typ_, func(u Type) bool {
                        uch, _ := u.(*Chan)
                        if uch == nil {
                                check.errorf(x, InvalidClose, invalidOp+"cannot close non-channel %s", x)
@@ -267,7 +267,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
                x.mode = novalue
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(nil, x.typ_))
                }
 
        case _Complex:
@@ -276,10 +276,10 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
                // convert or check untyped arguments
                d := 0
-               if isUntyped(x.typ) {
+               if isUntyped(x.typ_) {
                        d |= 1
                }
-               if isUntyped(y.typ) {
+               if isUntyped(y.typ_) {
                        d |= 2
                }
                switch d {
@@ -287,10 +287,10 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        // x and y are typed => nothing to do
                case 1:
                        // only x is untyped => convert to type of y
-                       check.convertUntyped(x, y.typ)
+                       check.convertUntyped(x, y.typ_)
                case 2:
                        // only y is untyped => convert to type of x
-                       check.convertUntyped(y, x.typ)
+                       check.convertUntyped(y, x.typ_)
                case 3:
                        // x and y are untyped =>
                        // 1) if both are constants, convert them to untyped
@@ -302,8 +302,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        //    because shifts of floats are not permitted)
                        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]
+                                       if isNumeric(x.typ_) && constant.Sign(constant.Imag(x.val)) == 0 {
+                                               x.typ_ = Typ[UntypedFloat]
                                        }
                                }
                                toFloat(x)
@@ -320,8 +320,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                // both argument types must be identical
-               if !Identical(x.typ, y.typ) {
-                       check.errorf(x, InvalidComplex, invalidOp+"%v (mismatched types %s and %s)", call, x.typ, y.typ)
+               if !Identical(x.typ_, y.typ_) {
+                       check.errorf(x, InvalidComplex, invalidOp+"%v (mismatched types %s and %s)", call, x.typ_, y.typ_)
                        return
                }
 
@@ -343,7 +343,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
                resTyp := check.applyTypeFunc(f, x, id)
                if resTyp == nil {
-                       check.errorf(x, InvalidComplex, invalidArg+"arguments have type %s, expected floating-point", x.typ)
+                       check.errorf(x, InvalidComplex, invalidArg+"arguments have type %s, expected floating-point", x.typ_)
                        return
                }
 
@@ -355,10 +355,10 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                if check.recordTypes() && x.mode != constant_ {
-                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ_, x.typ_))
                }
 
-               x.typ = resTyp
+               x.typ_ = resTyp
 
        case _Copy:
                // copy(x, y []E) int
@@ -375,7 +375,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                var special bool
                if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
                        special = true
-                       for _, u := range typeset(y.typ) {
+                       for _, u := range typeset(y.typ_) {
                                if s, _ := u.(*Slice); s != nil && Identical(s.elem, universeByte) {
                                        // typeset ⊇ {[]byte}
                                } else if isString(u) {
@@ -399,7 +399,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        srcE, err := sliceElem(y)
                        if err != nil {
                                // If we have a string, for a better error message proceed with byte element type.
-                               if !allString(y.typ) {
+                               if !allString(y.typ_) {
                                        check.errorf(y, InvalidCopy, "invalid copy: %s", err.format(check))
                                        return
                                }
@@ -412,16 +412,16 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ, y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ_, y.typ_))
                }
                x.mode = value
-               x.typ = Typ[Int]
+               x.typ_ = Typ[Int]
 
        case _Delete:
                // delete(map_, key)
                // map_ must be a map type or a type parameter describing map types.
                // The key cannot be a type parameter for now.
-               map_ := x.typ
+               map_ := x.typ_
                var key Type
                if !underIs(map_, func(u Type) bool {
                        map_, _ := u.(*Map)
@@ -455,12 +455,12 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // real(complexT) floatT
 
                // convert or check untyped argument
-               if isUntyped(x.typ) {
+               if isUntyped(x.typ_) {
                        if x.mode == constant_ {
                                // an untyped constant number can always be considered
                                // as a complex constant
-                               if isNumeric(x.typ) {
-                                       x.typ = Typ[UntypedComplex]
+                               if isNumeric(x.typ_) {
+                                       x.typ_ = Typ[UntypedComplex]
                                }
                        } else {
                                // an untyped non-constant argument may appear if
@@ -497,7 +497,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        if id == _Real {
                                code = InvalidReal
                        }
-                       check.errorf(x, code, invalidArg+"argument has type %s, expected complex type", x.typ)
+                       check.errorf(x, code, invalidArg+"argument has type %s, expected complex type", x.typ_)
                        return
                }
 
@@ -513,10 +513,10 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                if check.recordTypes() && x.mode != constant_ {
-                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(resTyp, x.typ_))
                }
 
-               x.typ = resTyp
+               x.typ_ = resTyp
 
        case _Make:
                // make(T, n)
@@ -572,9 +572,9 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        // safe to continue
                }
                x.mode = value
-               x.typ = T
+               x.typ_ = T
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, types...))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, types...))
                }
 
        case _Max, _Min:
@@ -592,7 +592,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                return
                        }
 
-                       if !allOrdered(a.typ) {
+                       if !allOrdered(a.typ_) {
                                check.errorf(a, InvalidMinMaxOperand, invalidArg+"%s cannot be ordered", a)
                                return
                        }
@@ -604,8 +604,8 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                        return
                                }
 
-                               if !Identical(x.typ, a.typ) {
-                                       check.errorf(a, MismatchedTypes, invalidArg+"mismatched types %s (previous argument) and %s (type of %s)", x.typ, a.typ, a.expr)
+                               if !Identical(x.typ_, a.typ_) {
+                                       check.errorf(a, MismatchedTypes, invalidArg+"mismatched types %s (previous argument) and %s (type of %s)", x.typ_, a.typ_, a.expr)
                                        return
                                }
 
@@ -631,15 +631,15 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
                // Use the final type computed above for all arguments.
                for _, a := range args {
-                       check.updateExprType(a.expr, x.typ, true)
+                       check.updateExprType(a.expr, x.typ_, true)
                }
 
                if check.recordTypes() && x.mode != constant_ {
                        types := make([]Type, nargs)
                        for i := range types {
-                               types[i] = x.typ
+                               types[i] = x.typ_
                        }
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, types...))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, types...))
                }
 
        case _New:
@@ -653,26 +653,26 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        return
                case typexpr:
                        // new(T)
-                       check.validVarType(arg, x.typ)
+                       check.validVarType(arg, x.typ_)
                default:
                        // new(expr)
-                       if isUntyped(x.typ) {
+                       if isUntyped(x.typ_) {
                                // check for overflow and untyped nil
                                check.assignment(x, nil, "argument to new")
                                if x.mode == invalid {
                                        return
                                }
-                               assert(isTyped(x.typ))
+                               assert(isTyped(x.typ_))
                        }
                        // report version error only if there are no other errors
                        check.verifyVersionf(call.Fun, go1_26, "new(%s)", arg)
                }
 
-               T := x.typ
+               T := x.typ_
                x.mode = value
-               x.typ = NewPointer(T)
+               x.typ_ = NewPointer(T)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, T))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, T))
                }
 
        case _Panic:
@@ -711,7 +711,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                if a.mode == invalid {
                                        return
                                }
-                               params[i] = a.typ
+                               params[i] = a.typ_
                        }
                }
 
@@ -723,9 +723,9 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        case _Recover:
                // recover() interface{}
                x.mode = value
-               x.typ = &emptyInterface
+               x.typ_ = &emptyInterface
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_))
                }
 
        case _Add:
@@ -743,9 +743,9 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                x.mode = value
-               x.typ = Typ[UnsafePointer]
+               x.typ_ = Typ[UnsafePointer]
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, x.typ, y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, x.typ_, y.typ_))
                }
 
        case _Alignof:
@@ -755,17 +755,17 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        return
                }
 
-               if check.hasVarSize(x.typ) {
+               if check.hasVarSize(x.typ_) {
                        x.mode = value
                        if check.recordTypes() {
-                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ))
+                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ_))
                        }
                } else {
                        x.mode = constant_
-                       x.val = constant.MakeInt64(check.conf.alignof(x.typ))
+                       x.val = constant.MakeInt64(check.conf.alignof(x.typ_))
                        // result is constant - no need to record signature
                }
-               x.typ = Typ[Uintptr]
+               x.typ_ = Typ[Uintptr]
 
        case _Offsetof:
                // unsafe.Offsetof(x T) uintptr, where x must be a selector
@@ -783,7 +783,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        return
                }
 
-               base := derefStructPtr(x.typ)
+               base := derefStructPtr(x.typ_)
                sel := selx.Sel.Name
                obj, index, indirect := lookupFieldOrMethod(base, false, check.pkg, sel, false)
                switch obj.(type) {
@@ -834,7 +834,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        x.val = constant.MakeInt64(offs)
                        // result is constant - no need to record signature
                }
-               x.typ = Typ[Uintptr]
+               x.typ_ = Typ[Uintptr]
 
        case _Sizeof:
                // unsafe.Sizeof(x T) uintptr
@@ -843,13 +843,13 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        return
                }
 
-               if check.hasVarSize(x.typ) {
+               if check.hasVarSize(x.typ_) {
                        x.mode = value
                        if check.recordTypes() {
-                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ))
+                               check.recordBuiltinType(call.Fun, makeSig(Typ[Uintptr], x.typ_))
                        }
                } else {
-                       size := check.conf.sizeof(x.typ)
+                       size := check.conf.sizeof(x.typ_)
                        if size < 0 {
                                check.errorf(x, TypeTooLarge, "%s is too large", x)
                                return
@@ -858,13 +858,13 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        x.val = constant.MakeInt64(size)
                        // result is constant - no need to record signature
                }
-               x.typ = Typ[Uintptr]
+               x.typ_ = Typ[Uintptr]
 
        case _Slice:
                // unsafe.Slice(ptr *T, len IntegerType) []T
                check.verifyVersionf(call.Fun, go1_17, "unsafe.Slice")
 
-               u, _ := commonUnder(x.typ, nil)
+               u, _ := commonUnder(x.typ_, nil)
                ptr, _ := u.(*Pointer)
                if ptr == nil {
                        check.errorf(x, InvalidUnsafeSlice, invalidArg+"%s is not a pointer", x)
@@ -877,16 +877,16 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                x.mode = value
-               x.typ = NewSlice(ptr.base)
+               x.typ_ = NewSlice(ptr.base)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, ptr, y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, ptr, y.typ_))
                }
 
        case _SliceData:
                // unsafe.SliceData(slice []T) *T
                check.verifyVersionf(call.Fun, go1_20, "unsafe.SliceData")
 
-               u, _ := commonUnder(x.typ, nil)
+               u, _ := commonUnder(x.typ_, nil)
                slice, _ := u.(*Slice)
                if slice == nil {
                        check.errorf(x, InvalidUnsafeSliceData, invalidArg+"%s is not a slice", x)
@@ -894,9 +894,9 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                x.mode = value
-               x.typ = NewPointer(slice.elem)
+               x.typ_ = NewPointer(slice.elem)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, slice))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, slice))
                }
 
        case _String:
@@ -914,9 +914,9 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                x.mode = value
-               x.typ = Typ[String]
+               x.typ_ = Typ[String]
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, NewPointer(universeByte), y.typ))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, NewPointer(universeByte), y.typ_))
                }
 
        case _StringData:
@@ -929,16 +929,16 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                x.mode = value
-               x.typ = NewPointer(universeByte)
+               x.typ_ = NewPointer(universeByte)
                if check.recordTypes() {
-                       check.recordBuiltinType(call.Fun, makeSig(x.typ, Typ[String]))
+                       check.recordBuiltinType(call.Fun, makeSig(x.typ_, Typ[String]))
                }
 
        case _Assert:
                // 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
                }
@@ -987,7 +987,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 // or a type error if x is not a slice (or a type set of slices).
 func sliceElem(x *operand) (Type, *typeError) {
        var E Type
-       for _, u := range typeset(x.typ) {
+       for _, u := range typeset(x.typ_) {
                s, _ := u.(*Slice)
                if s == nil {
                        if x.isNil() {
@@ -1073,7 +1073,7 @@ func (check *Checker) hasVarSize(t Type) bool {
 // applyTypeFunc returns nil.
 // If x is not a type parameter, the result is f(x).
 func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId) Type {
-       if tp, _ := Unalias(x.typ).(*TypeParam); tp != nil {
+       if tp, _ := Unalias(x.typ_).(*TypeParam); tp != nil {
                // Test if t satisfies the requirements for the argument
                // type and collect possible result types at the same time.
                var terms []*Term
@@ -1117,7 +1117,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                return ptyp
        }
 
-       return f(x.typ)
+       return f(x.typ_)
 }
 
 // makeSig makes a signature for the given argument and result types.
index 978a7ca3cc5c0bee66a2a5fc53ed686ebf832b2d..364800c66cd460d829f11e9a24154455699f4055 100644 (file)
@@ -59,7 +59,7 @@ func (check *Checker) funcInst(T *target, pos token.Pos, x *operand, ix *indexed
        // Check the number of type arguments (got) vs number of type parameters (want).
        // Note that x is a function value, not a type expression, so we don't need to
        // call Underlying below.
-       sig := x.typ.(*Signature)
+       sig := x.typ_.(*Signature)
        got, want := len(targs), sig.TypeParams().Len()
        if got > want {
                // Providing too many type arguments is always an error.
@@ -101,7 +101,7 @@ func (check *Checker) funcInst(T *target, pos token.Pos, x *operand, ix *indexed
                        // that makes sense when reported in error messages from infer, below.
                        expr := ast.NewIdent(T.desc)
                        expr.NamePos = x.Pos() // correct position
-                       args = []*operand{{mode: value, expr: expr, typ: T.sig}}
+                       args = []*operand{{mode: value, expr: expr, typ_: T.sig}}
                        reverse = true
                }
 
@@ -124,7 +124,7 @@ func (check *Checker) funcInst(T *target, pos token.Pos, x *operand, ix *indexed
 
        // instantiate function signature
        sig = check.instantiateSignature(x.Pos(), x.expr, sig, targs, xlist)
-       x.typ = sig
+       x.typ_ = sig
        x.mode = value
        return nil
 }
@@ -199,7 +199,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
                if x.mode == invalid {
                        return conversion
                }
-               T := x.typ
+               T := x.typ_
                x.mode = invalid
                // We cannot convert a value to an incomplete type; make sure it's complete.
                if !check.isComplete(T) {
@@ -251,7 +251,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
 
        // 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.
-       u, err := commonUnder(x.typ, func(t, u Type) *typeError {
+       u, err := commonUnder(x.typ_, func(t, u Type) *typeError {
                if _, ok := u.(*Signature); u != nil && !ok {
                        return typeErrorf("%s is not a function", t)
                }
@@ -333,17 +333,17 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
                        x.expr = call
                        return statement
                }
-               x.typ = typ
+               x.typ_ = typ
        default:
                x.mode = value
-               x.typ = sig.results
+               x.typ_ = sig.results
        }
        x.expr = call
        check.hasCallOrRecv = true
 
        // 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
        }
 
@@ -382,7 +382,7 @@ func (check *Checker) genericExprList(elist []ast.Expr) (resList []*operand, tar
                                if i < len(targsList) {
                                        if n := len(targsList[i]); n > 0 {
                                                // x must be a partially instantiated function
-                                               assert(n < x.typ.(*Signature).TypeParams().Len())
+                                               assert(n < x.typ_.(*Signature).TypeParams().Len())
                                        }
                                }
                        }
@@ -419,11 +419,11 @@ 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 {
-                                       resList[i] = &operand{mode: value, expr: e, typ: v.typ}
+                                       resList[i] = &operand{mode: value, expr: e, typ_: v.typ}
                                }
                        } else {
                                // x is exactly one value (possibly invalid or uninstantiated generic function).
@@ -582,7 +582,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
        if enableReverseTypeInference {
                for i, arg := range args {
                        // generic arguments cannot have a defined (*Named) type - no need for underlying type below
-                       if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
+                       if asig, _ := arg.typ_.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
                                // The argument type is a generic function signature. This type is
                                // pointer-identical with (it's copied from) the type of the generic
                                // function argument and thus the function object.
@@ -597,7 +597,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
                                atparams, tmp := check.renameTParams(call.Pos(), asig.TypeParams().list(), asig)
                                asig = tmp.(*Signature)
                                asig.tparams = &TypeParamList{atparams} // renameTParams doesn't touch associated type parameters
-                               arg.typ = asig                          // new type identity for the function argument
+                               arg.typ_ = asig                         // new type identity for the function argument
                                tparams = append(tparams, atparams...)
                                // add partial list of type arguments, if any
                                if i < len(atargs) {
@@ -652,11 +652,11 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
                j := n
                for _, i := range genericArgs {
                        arg := args[i]
-                       asig := arg.typ.(*Signature)
+                       asig := arg.typ_.(*Signature)
                        k := j + asig.TypeParams().Len()
                        // targs[j:k] are the inferred type arguments for asig
-                       arg.typ = check.instantiateSignature(call.Pos(), arg.expr, asig, targs[j:k], nil) // TODO(gri) provide xlist if possible (partial instantiations)
-                       check.record(arg)                                                                 // record here because we didn't use the usual expr evaluators
+                       arg.typ_ = check.instantiateSignature(call.Pos(), arg.expr, asig, targs[j:k], nil) // TODO(gri) provide xlist if possible (partial instantiations)
+                       check.record(arg)                                                                  // record here because we didn't use the usual expr evaluators
                        j = k
                }
        }
@@ -758,27 +758,27 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                        case *Const:
                                assert(exp.Val() != nil)
                                x.mode = constant_
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                x.val = exp.val
                        case *TypeName:
                                x.mode = typexpr
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                        case *Var:
                                x.mode = variable
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                if pkg.cgo && strings.HasPrefix(exp.name, "_Cvar_") {
-                                       x.typ = x.typ.(*Pointer).base
+                                       x.typ_ = x.typ_.(*Pointer).base
                                }
                        case *Func:
                                x.mode = funcMode
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                if pkg.cgo && strings.HasPrefix(exp.name, "_Cmacro_") {
                                        x.mode = value
-                                       x.typ = x.typ.(*Signature).results.vars[0].typ
+                                       x.typ_ = x.typ_.(*Signature).results.vars[0].typ
                                }
                        case *Builtin:
                                x.mode = builtin
-                               x.typ = exp.typ
+                               x.typ_ = exp.typ
                                x.id = exp.id
                        default:
                                check.dump("%v: unexpected object %v", e.Sel.Pos(), exp)
@@ -800,7 +800,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
        }
 
        // We cannot select on an incomplete type; make sure it's complete.
-       if !check.isComplete(x.typ) {
+       if !check.isComplete(x.typ_) {
                goto Error
        }
 
@@ -821,14 +821,14 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
 
        // Additionally, if x.typ is a pointer type, selecting implicitly dereferences the value, meaning
        // its base type must also be complete.
-       if p, ok := x.typ.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
+       if p, ok := x.typ_.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
                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()) {
+               if !isValid(x.typ_.Underlying()) {
                        goto Error
                }
 
@@ -840,19 +840,19 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
 
                if indirect {
                        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)
+                               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)
+                               check.errorf(e.Sel, InvalidMethodExpr, "cannot call pointer method %s on %s", sel, x.typ_)
                        }
                        goto Error
                }
 
                var why string
-               if isInterfacePtr(x.typ) {
-                       why = check.interfacePtrError(x.typ)
+               if isInterfacePtr(x.typ_) {
+                       why = check.interfacePtrError(x.typ_)
                } else {
-                       alt, _, _ := lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel, true)
-                       why = check.lookupError(x.typ, sel, alt, false)
+                       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)
                goto Error
@@ -862,18 +862,18 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
        switch obj := obj.(type) {
        case *Var:
                if x.mode == typexpr {
-                       check.errorf(e.X, MissingFieldOrMethod, "operand for field selector %s must be value of type %s", sel, x.typ)
+                       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)
+               check.recordSelection(e, FieldVal, x.typ_, obj, index, indirect)
                if x.mode == variable || indirect {
                        x.mode = variable
                } else {
                        x.mode = value
                }
-               x.typ = obj.typ
+               x.typ_ = obj.typ
 
        case *Func:
                check.objDecl(obj) // ensure fully set-up signature
@@ -881,7 +881,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
 
                if x.mode == typexpr {
                        // method expression
-                       check.recordSelection(e, MethodExpr, x.typ, obj, index, indirect)
+                       check.recordSelection(e, MethodExpr, x.typ_, obj, index, indirect)
 
                        sig := obj.typ.(*Signature)
                        if sig.recv == nil {
@@ -909,9 +909,9 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                                        name = "_"
                                }
                        }
-                       params = append([]*Var{NewParam(sig.recv.pos, sig.recv.pkg, name, x.typ)}, params...)
+                       params = append([]*Var{NewParam(sig.recv.pos, sig.recv.pkg, name, x.typ_)}, params...)
                        x.mode = value
-                       x.typ = &Signature{
+                       x.typ_ = &Signature{
                                tparams:  sig.tparams,
                                params:   NewTuple(params...),
                                results:  sig.results,
@@ -922,7 +922,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
 
                        // TODO(gri) If we needed to take into account the receiver's
                        // addressability, should we report the type &(x.typ) instead?
-                       check.recordSelection(e, MethodVal, x.typ, obj, index, indirect)
+                       check.recordSelection(e, MethodVal, x.typ_, obj, index, indirect)
 
                        // TODO(gri) The verification pass below is disabled for now because
                        //           method sets don't match method lookup in some cases.
@@ -937,7 +937,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                                // _before_ calling NewMethodSet: LookupFieldOrMethod completes
                                // any incomplete interfaces so they are available to NewMethodSet
                                // (which assumes that interfaces have been completed already).
-                               typ := x.typ
+                               typ := x.typ_
                                if x.mode == variable {
                                        // If typ is not an (unnamed) pointer or an interface,
                                        // use *typ instead, because the method set of *typ
@@ -974,7 +974,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
                        // remove receiver
                        sig := *obj.typ.(*Signature)
                        sig.recv = nil
-                       x.typ = &sig
+                       x.typ_ = &sig
                }
 
        default:
@@ -987,7 +987,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, wantType bool) {
 
 Error:
        x.mode = invalid
-       x.typ = Typ[Invalid]
+       x.typ_ = Typ[Invalid]
        x.expr = e
 }
 
index dc9efa0130eae3f158ec1383973bf2cd9b2b31e8..b210587e8a9f7e13cdc762a9e5b81c52bcdb665b 100644 (file)
@@ -34,8 +34,8 @@ func (check *Checker) overflow(x *operand, opPos token.Pos) {
        // their type after each constant operation.
        // x.typ cannot be a type parameter (type
        // parameters cannot be constant types).
-       if isTyped(x.typ) {
-               check.representable(x, x.typ.Underlying().(*Basic))
+       if isTyped(x.typ_) {
+               check.representable(x, x.typ_.Underlying().(*Basic))
                return
        }
 
@@ -255,7 +255,7 @@ func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, Co
        assert(x.mode == constant_)
        v := x.val
        if !representableConst(x.val, check, typ, &v) {
-               if isNumeric(x.typ) && isNumeric(typ) {
+               if isNumeric(x.typ_) && isNumeric(typ) {
                        // numeric conversion : error msg
                        //
                        // integer -> integer : overflows
@@ -263,7 +263,7 @@ func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, Co
                        // float   -> integer : truncated
                        // float   -> float   : overflows
                        //
-                       if !isInteger(x.typ) && isInteger(typ) {
+                       if !isInteger(x.typ_) && isInteger(typ) {
                                return nil, TruncatedFloat
                        } else {
                                return nil, NumericOverflow
@@ -301,8 +301,8 @@ func (check *Checker) convertUntyped(x *operand, target Type) {
                x.val = val
                check.updateExprVal(x.expr, val)
        }
-       if newType != x.typ {
-               x.typ = newType
+       if newType != x.typ_ {
+               x.typ_ = newType
                check.updateExprType(x.expr, newType, false)
        }
 }
index daef80adf8058b8b3b2fca4721898862b5685685..a0bf21102439dc608eefe8af0da1798188f272b0 100644 (file)
@@ -26,7 +26,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                        // nothing to do
                case representableConst(x.val, check, t, val):
                        return true
-               case isInteger(x.typ) && isString(t):
+               case isInteger(x.typ_) && isString(t):
                        codepoint := unicode.ReplacementChar
                        if i, ok := constant.Uint64Val(x.val); ok && i <= unicode.MaxRune {
                                codepoint = rune(i)
@@ -48,7 +48,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                // A conversion from an integer constant to an integer type
                // can only fail if there's overflow. Give a concise error.
                // (go.dev/issue/63563)
-               if !ok && isInteger(x.typ) && isInteger(T) {
+               if !ok && isInteger(x.typ_) && isInteger(T) {
                        check.errorf(x, InvalidConversion, "constant %s overflows %s", x.val, T)
                        x.mode = invalid
                        return
@@ -65,11 +65,11 @@ func (check *Checker) conversion(x *operand, T Type) {
                                cause = check.sprintf("%s does not contain specific types", T)
                                return false
                        }
-                       if isString(x.typ) && isBytesOrRunes(u) {
+                       if isString(x.typ_) && isBytesOrRunes(u) {
                                return true
                        }
                        if !constConvertibleTo(u, nil) {
-                               if isInteger(x.typ) && isInteger(u) {
+                               if isInteger(x.typ_) && isInteger(u) {
                                        // see comment above on constant conversion
                                        cause = check.sprintf("constant %s overflows %s (in %s)", x.val, u, T)
                                } else {
@@ -99,7 +99,7 @@ func (check *Checker) conversion(x *operand, T Type) {
        // The conversion argument types are final. For untyped values the
        // conversion provides the type, per the spec: "A constant may be
        // given a type explicitly by a constant declaration or conversion,...".
-       if isUntyped(x.typ) {
+       if isUntyped(x.typ_) {
                final := T
                // - For conversions to interfaces, except for untyped nil arguments
                //   and isTypes2, use the argument's default type.
@@ -109,17 +109,17 @@ func (check *Checker) conversion(x *operand, T Type) {
                // - If !isTypes2, keep untyped nil for untyped nil arguments.
                // - For constant integer to string conversions, keep the argument type.
                //   (See also the TODO below.)
-               if isTypes2 && x.typ == Typ[UntypedNil] {
+               if isTypes2 && x.typ_ == Typ[UntypedNil] {
                        // 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) {
-                       final = x.typ
+                       final = Default(x.typ_) // default type of untyped nil is untyped nil
+               } else if x.mode == constant_ && isInteger(x.typ_) && allString(T) {
+                       final = x.typ_
                }
                check.updateExprType(x.expr, final, true)
        }
 
-       x.typ = T
+       x.typ_ = T
 }
 
 // TODO(gri) convertibleTo checks if T(x) is valid. It assumes that the type
@@ -143,7 +143,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
        }
 
        origT := T
-       V := Unalias(x.typ)
+       V := Unalias(x.typ_)
        T = Unalias(T)
        Vu := V.Underlying()
        Tu := T.Underlying()
@@ -253,7 +253,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
                        if V == nil {
                                return false // no specific types
                        }
-                       x.typ = V.typ
+                       x.typ_ = V.typ
                        return Tp.is(func(T *term) bool {
                                if T == nil {
                                        return false // no specific types
@@ -271,7 +271,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
                        if V == nil {
                                return false // no specific types
                        }
-                       x.typ = V.typ
+                       x.typ_ = V.typ
                        if !x.convertibleTo(check, T, cause) {
                                errorf("cannot convert %s (in %s) to type %s", V.typ, Vp, origT)
                                return false
@@ -284,7 +284,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
                                return false // no specific types
                        }
                        if !x.convertibleTo(check, T.typ, cause) {
-                               errorf("cannot convert %s to type %s (in %s)", x.typ, T.typ, Tp)
+                               errorf("cannot convert %s to type %s (in %s)", x.typ_, T.typ, Tp)
                                return false
                        }
                        return true
index f096b2a47e8862e40c196ba17deb61473fd06b07..e24693f1b68fb2b377edd570fe41a9da73b4bc7d 100644 (file)
@@ -72,7 +72,7 @@ func init() {
 
 func (check *Checker) op(m opPredicates, x *operand, op token.Token) bool {
        if pred := m[op]; pred != nil {
-               if !pred(x.typ) {
+               if !pred(x.typ_) {
                        check.errorf(x, UndefinedOp, invalidOp+"operator %s not defined on %s", op, x)
                        return false
                }
@@ -143,14 +143,14 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
                        return
                }
                x.mode = value
-               x.typ = &Pointer{base: x.typ}
+               x.typ_ = &Pointer{base: x.typ_}
                return
 
        case token.ARROW:
                // We cannot receive a value with an incomplete type; make sure it's complete.
                if elem := check.chanElem(x, x, true); elem != nil && check.isComplete(elem) {
                        x.mode = commaok
-                       x.typ = elem
+                       x.typ_ = elem
                        check.hasCallOrRecv = true
                        return
                }
@@ -159,7 +159,7 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
 
        case token.TILDE:
                // Provide a better error position and message than what check.op below would do.
-               if !allInteger(x.typ) {
+               if !allInteger(x.typ_) {
                        check.error(e, UndefinedOp, "cannot use ~ outside of interface or type constraint")
                        x.mode = invalid
                        return
@@ -179,8 +179,8 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
                        return
                }
                var prec uint
-               if isUnsigned(x.typ) {
-                       prec = uint(check.conf.sizeof(x.typ) * 8)
+               if isUnsigned(x.typ_) {
+                       prec = uint(check.conf.sizeof(x.typ_) * 8)
                }
                x.val = constant.UnaryOp(op, x.val, prec)
                x.expr = e
@@ -196,7 +196,7 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr) {
 // or send to x (recv == false) operation. If the operation is not valid, chanElem
 // reports an error and returns nil.
 func (check *Checker) chanElem(pos positioner, x *operand, recv bool) Type {
-       u, err := commonUnder(x.typ, func(t, u Type) *typeError {
+       u, err := commonUnder(x.typ_, func(t, u Type) *typeError {
                if u == nil {
                        return typeErrorf("no specific channel type")
                }
@@ -219,14 +219,14 @@ func (check *Checker) chanElem(pos positioner, x *operand, recv bool) Type {
 
        cause := err.format(check)
        if recv {
-               if isTypeParam(x.typ) {
+               if isTypeParam(x.typ_) {
                        check.errorf(pos, InvalidReceive, invalidOp+"cannot receive from %s: %s", x, cause)
                } else {
                        // In this case, only the non-channel and send-only channel error are possible.
                        check.errorf(pos, InvalidReceive, invalidOp+"cannot receive from %s %s", cause, x)
                }
        } else {
-               if isTypeParam(x.typ) {
+               if isTypeParam(x.typ_) {
                        check.errorf(pos, InvalidSend, invalidOp+"cannot send to %s: %s", x, cause)
                } else {
                        // In this case, only the non-channel and receive-only channel error are possible.
@@ -386,14 +386,14 @@ 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) {
-               return x.typ, nil, 0
+       if x.mode == invalid || isTyped(x.typ_) || !isValid(target) {
+               return x.typ_, nil, 0
        }
        // x is untyped
 
        if isUntyped(target) {
                // both x and target are untyped
-               if m := maxType(x.typ, target); m != nil {
+               if m := maxType(x.typ_, target); m != nil {
                        return m, nil, 0
                }
                return nil, nil, InvalidUntypedConversion
@@ -412,7 +412,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
                // result of comparisons (untyped bool), intermediate
                // (delayed-checked) rhs operands of shifts, and as
                // the value nil.
-               switch x.typ.(*Basic).kind {
+               switch x.typ_.(*Basic).kind {
                case UntypedBool:
                        if !isBoolean(target) {
                                return nil, nil, InvalidUntypedConversion
@@ -466,7 +466,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
                if !u.Empty() {
                        return nil, nil, InvalidUntypedConversion
                }
-               return Default(x.typ), nil, 0
+               return Default(x.typ_), nil, 0
        case *Pointer, *Signature, *Slice, *Map, *Chan:
                if !x.isNil() {
                        return nil, nil, InvalidUntypedConversion
@@ -482,7 +482,7 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
 // If switchCase is true, the operator op is ignored.
 func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool) {
        // Avoid spurious errors if any of the operands has an invalid type (go.dev/issue/54405).
-       if !isValid(x.typ) || !isValid(y.typ) {
+       if !isValid(x.typ_) || !isValid(y.typ_) {
                x.mode = invalid
                return
        }
@@ -497,16 +497,16 @@ func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool)
        // spec: "In any comparison, the first operand must be assignable
        // to the type of the second operand, or vice versa."
        code := MismatchedTypes
-       ok, _ := x.assignableTo(check, y.typ, nil)
+       ok, _ := x.assignableTo(check, y.typ_, nil)
        if !ok {
-               ok, _ = y.assignableTo(check, x.typ, nil)
+               ok, _ = y.assignableTo(check, x.typ_, nil)
        }
        if !ok {
                // Report the error on the 2nd operand since we only
                // know after seeing the 2nd operand whether we have
                // a type mismatch.
                errOp = y
-               cause = check.sprintf("mismatched types %s and %s", x.typ, y.typ)
+               cause = check.sprintf("mismatched types %s and %s", x.typ_, y.typ_)
                goto Error
        }
 
@@ -518,9 +518,9 @@ func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool)
                switch {
                case x.isNil() || y.isNil():
                        // Comparison against nil requires that the other operand type has nil.
-                       typ := x.typ
+                       typ := x.typ_
                        if x.isNil() {
-                               typ = y.typ
+                               typ = y.typ_
                        }
                        if !hasNil(typ) {
                                // This case should only be possible for "nil == nil".
@@ -531,24 +531,24 @@ func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool)
                                goto Error
                        }
 
-               case !Comparable(x.typ):
+               case !Comparable(x.typ_):
                        errOp = x
-                       cause = check.incomparableCause(x.typ)
+                       cause = check.incomparableCause(x.typ_)
                        goto Error
 
-               case !Comparable(y.typ):
+               case !Comparable(y.typ_):
                        errOp = y
-                       cause = check.incomparableCause(y.typ)
+                       cause = check.incomparableCause(y.typ_)
                        goto Error
                }
 
        case token.LSS, token.LEQ, token.GTR, token.GEQ:
                // spec: The ordering operators <, <=, >, and >= apply to operands that are ordered."
                switch {
-               case !allOrdered(x.typ):
+               case !allOrdered(x.typ_):
                        errOp = x
                        goto Error
-               case !allOrdered(y.typ):
+               case !allOrdered(y.typ_):
                        errOp = y
                        goto Error
                }
@@ -568,29 +568,29 @@ func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool)
                // time will be materialized. Update the expression trees.
                // If the current types are untyped, the materialized type
                // is the respective default type.
-               check.updateExprType(x.expr, Default(x.typ), true)
-               check.updateExprType(y.expr, Default(y.typ), true)
+               check.updateExprType(x.expr, Default(x.typ_), true)
+               check.updateExprType(y.expr, Default(y.typ_), true)
        }
 
        // spec: "Comparison operators compare two operands and yield
        //        an untyped boolean value."
-       x.typ = Typ[UntypedBool]
+       x.typ_ = Typ[UntypedBool]
        return
 
 Error:
        // We have an offending operand errOp and possibly an error cause.
        if cause == "" {
-               if isTypeParam(x.typ) || isTypeParam(y.typ) {
+               if isTypeParam(x.typ_) || isTypeParam(y.typ_) {
                        // TODO(gri) should report the specific type causing the problem, if any
-                       if !isTypeParam(x.typ) {
+                       if !isTypeParam(x.typ_) {
                                errOp = y
                        }
-                       cause = check.sprintf("type parameter %s cannot use operator %s", errOp.typ, op)
+                       cause = check.sprintf("type parameter %s cannot use operator %s", errOp.typ_, op)
                } else {
                        // catch-all neither x nor y is a type parameter
-                       what := compositeKind(errOp.typ)
+                       what := compositeKind(errOp.typ_)
                        if what == "" {
-                               what = check.sprintf("%s", errOp.typ)
+                               what = check.sprintf("%s", errOp.typ_)
                        }
                        cause = check.sprintf("operator %s not defined on %s", op, what)
                }
@@ -623,7 +623,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                xval = constant.ToInt(x.val)
        }
 
-       if allInteger(x.typ) || isUntyped(x.typ) && xval != nil && xval.Kind() == constant.Int {
+       if allInteger(x.typ_) || isUntyped(x.typ_) && xval != nil && xval.Kind() == constant.Int {
                // The lhs is of integer type or an untyped constant representable
                // as an integer. Nothing to do.
        } else {
@@ -648,7 +648,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                        return
                }
 
-               if isUntyped(y.typ) {
+               if isUntyped(y.typ_) {
                        // 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])
@@ -660,12 +660,12 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
        } else {
                // Check that RHS is otherwise at least of integer type.
                switch {
-               case allInteger(y.typ):
-                       if !allUnsigned(y.typ) && !check.verifyVersionf(y, go1_13, invalidOp+"signed shift count %s", y) {
+               case allInteger(y.typ_):
+                       if !allUnsigned(y.typ_) && !check.verifyVersionf(y, go1_13, invalidOp+"signed shift count %s", y) {
                                x.mode = invalid
                                return
                        }
-               case isUntyped(y.typ):
+               case isUntyped(y.typ_):
                        // This is incorrect, but preserves pre-existing behavior.
                        // See also go.dev/issue/47410.
                        check.convertUntyped(y, Typ[Uint])
@@ -686,8 +686,8 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                        if x.val.Kind() == constant.Unknown || y.val.Kind() == constant.Unknown {
                                x.val = constant.MakeUnknown()
                                // ensure the correct type - see comment below
-                               if !isInteger(x.typ) {
-                                       x.typ = Typ[UntypedInt]
+                               if !isInteger(x.typ_) {
+                                       x.typ_ = Typ[UntypedInt]
                                }
                                return
                        }
@@ -703,8 +703,8 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                        // (e.g., 2.0, an untyped float) - this can only happen for untyped
                        // non-integer numeric constants. Correct the type so that the shift
                        // result is of integer type.
-                       if !isInteger(x.typ) {
-                               x.typ = Typ[UntypedInt]
+                       if !isInteger(x.typ_) {
+                               x.typ_ = Typ[UntypedInt]
                        }
                        // x is a constant so xval != nil and it must be of Int kind.
                        x.val = constant.Shift(xval, op, uint(s))
@@ -714,7 +714,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
                }
 
                // non-constant shift with constant lhs
-               if isUntyped(x.typ) {
+               if isUntyped(x.typ_) {
                        // spec: "If the left operand of a non-constant shift
                        // expression is an untyped constant, the type of the
                        // constant is what it would be if the shift expression
@@ -745,7 +745,7 @@ func (check *Checker) shift(x, y *operand, e ast.Expr, op token.Token) {
        }
 
        // non-constant shift - lhs must be an integer
-       if !allInteger(x.typ) {
+       if !allInteger(x.typ_) {
                check.errorf(x, InvalidShiftOperand, invalidOp+"shifted operand %s must be integer", x)
                x.mode = invalid
                return
@@ -807,18 +807,18 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
                return
        }
 
-       if !Identical(x.typ, y.typ) {
+       if !Identical(x.typ_, y.typ_) {
                // only report an error if we have valid types
                // (otherwise we had an error reported elsewhere already)
-               if isValid(x.typ) && isValid(y.typ) {
+               if isValid(x.typ_) && isValid(y.typ_) {
                        var posn positioner = x
                        if e != nil {
                                posn = e
                        }
                        if e != nil {
-                               check.errorf(posn, MismatchedTypes, invalidOp+"%s (mismatched types %s and %s)", e, x.typ, y.typ)
+                               check.errorf(posn, MismatchedTypes, invalidOp+"%s (mismatched types %s and %s)", e, x.typ_, y.typ_)
                        } else {
-                               check.errorf(posn, MismatchedTypes, invalidOp+"%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ, y.typ)
+                               check.errorf(posn, MismatchedTypes, invalidOp+"%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ_, y.typ_)
                        }
                }
                x.mode = invalid
@@ -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 {
@@ -858,7 +858,7 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
                        return
                }
                // force integer division of integer operands
-               if op == token.QUO && isInteger(x.typ) {
+               if op == token.QUO && isInteger(x.typ_) {
                        op = token.QUO_ASSIGN
                }
                x.val = constant.BinaryOp(x.val, op, y.val)
@@ -885,49 +885,49 @@ func (check *Checker) matchTypes(x, y *operand) {
        // not compatible, we report a type mismatch error.
        mayConvert := func(x, y *operand) bool {
                // If both operands are typed, there's no need for an implicit conversion.
-               if isTyped(x.typ) && isTyped(y.typ) {
+               if isTyped(x.typ_) && isTyped(y.typ_) {
                        return false
                }
                // A numeric type can only convert to another numeric type.
-               if allNumeric(x.typ) != allNumeric(y.typ) {
+               if allNumeric(x.typ_) != allNumeric(y.typ_) {
                        return false
                }
                // An untyped operand may convert to its default type when paired with an empty interface
                // TODO(gri) This should only matter for comparisons (the only binary operation that is
                //           valid with interfaces), but in that case the assignability check should take
                //           care of the conversion. Verify and possibly eliminate this extra test.
-               if isNonTypeParamInterface(x.typ) || isNonTypeParamInterface(y.typ) {
+               if isNonTypeParamInterface(x.typ_) || isNonTypeParamInterface(y.typ_) {
                        return true
                }
                // A boolean type can only convert to another boolean type.
-               if allBoolean(x.typ) != allBoolean(y.typ) {
+               if allBoolean(x.typ_) != allBoolean(y.typ_) {
                        return false
                }
                // A string type can only convert to another string type.
-               if allString(x.typ) != allString(y.typ) {
+               if allString(x.typ_) != allString(y.typ_) {
                        return false
                }
                // Untyped nil can only convert to a type that has a nil.
                if x.isNil() {
-                       return hasNil(y.typ)
+                       return hasNil(y.typ_)
                }
                if y.isNil() {
-                       return hasNil(x.typ)
+                       return hasNil(x.typ_)
                }
                // An untyped operand cannot convert to a pointer.
                // TODO(gri) generalize to type parameters
-               if isPointer(x.typ) || isPointer(y.typ) {
+               if isPointer(x.typ_) || isPointer(y.typ_) {
                        return false
                }
                return true
        }
 
        if mayConvert(x, y) {
-               check.convertUntyped(x, y.typ)
+               check.convertUntyped(x, y.typ_)
                if x.mode == invalid {
                        return
                }
-               check.convertUntyped(y, x.typ)
+               check.convertUntyped(y, x.typ_)
                if y.mode == invalid {
                        x.mode = invalid
                        return
@@ -999,7 +999,7 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
                return
        }
        var what string
-       switch t := x.typ.(type) {
+       switch t := x.typ_.(type) {
        case *Alias, *Named:
                if isGeneric(t) {
                        what = "type"
@@ -1016,7 +1016,7 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
        if what != "" {
                check.errorf(x.expr, WrongTypeArgCount, "cannot use generic %s %s without instantiation", what, x.expr)
                x.mode = invalid
-               x.typ = Typ[Invalid]
+               x.typ_ = Typ[Invalid]
        }
 }
 
@@ -1027,7 +1027,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
        // make sure x has a valid state in case of bailout
        // (was go.dev/issue/5770)
        x.mode = invalid
-       x.typ = Typ[Invalid]
+       x.typ_ = Typ[Invalid]
 
        switch e := e.(type) {
        case *ast.BadExpr:
@@ -1098,11 +1098,11 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
                        check.error(e, BadTypeKeyword, "use of .(type) outside type switch")
                        goto Error
                }
-               if isTypeParam(x.typ) {
+               if isTypeParam(x.typ_) {
                        check.errorf(x, InvalidAssert, invalidOp+"cannot use type assertion on type parameter value %s", x)
                        goto Error
                }
-               if _, ok := x.typ.Underlying().(*Interface); !ok {
+               if _, ok := x.typ_.Underlying().(*Interface); !ok {
                        check.errorf(x, InvalidAssert, invalidOp+"%s is not an interface", x)
                        goto Error
                }
@@ -1116,7 +1116,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
                }
                check.typeAssertion(e, x, T, false)
                x.mode = commaok
-               x.typ = T
+               x.typ_ = T
 
        case *ast.CallExpr:
                return check.callExpr(x, e)
@@ -1127,11 +1127,11 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
                case invalid:
                        goto Error
                case typexpr:
-                       check.validVarType(e.X, x.typ)
-                       x.typ = &Pointer{base: x.typ}
+                       check.validVarType(e.X, x.typ_)
+                       x.typ_ = &Pointer{base: x.typ_}
                default:
                        var base Type
-                       if !underIs(x.typ, func(u Type) bool {
+                       if !underIs(x.typ_, func(u Type) bool {
                                p, _ := u.(*Pointer)
                                if p == nil {
                                        check.errorf(x, InvalidIndirection, invalidOp+"cannot indirect %s", x)
@@ -1151,7 +1151,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
                                goto Error
                        }
                        x.mode = variable
-                       x.typ = base
+                       x.typ_ = base
                }
 
        case *ast.UnaryExpr:
@@ -1178,7 +1178,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e ast.Expr, hint Type)
        case *ast.ArrayType, *ast.StructType, *ast.FuncType,
                *ast.InterfaceType, *ast.MapType, *ast.ChanType:
                x.mode = typexpr
-               x.typ = check.typ(e)
+               x.typ_ = check.typ(e)
                // Note: rawExpr (caller of exprInternal) will call check.recordTypeAndValue
                // even though check.typ has already called it. This is fine as both
                // times the same expression and type are recorded. It is also not a
@@ -1244,7 +1244,7 @@ func keyVal(x constant.Value) any {
 // typeAssertion checks x.(T). The type of x must be an interface.
 func (check *Checker) typeAssertion(e ast.Expr, x *operand, T Type, typeSwitch bool) {
        var cause string
-       if check.assertableTo(x.typ, T, &cause) {
+       if check.assertableTo(x.typ_, T, &cause) {
                return // success
        }
 
@@ -1253,7 +1253,7 @@ func (check *Checker) typeAssertion(e ast.Expr, x *operand, T Type, typeSwitch b
                return
        }
 
-       check.errorf(e, ImpossibleAssert, "impossible type assertion: %s\n\t%s does not implement %s %s", e, T, x.typ, cause)
+       check.errorf(e, ImpossibleAssert, "impossible type assertion: %s\n\t%s does not implement %s %s", e, T, x.typ_, cause)
 }
 
 // expr typechecks expression e and initializes x with the expression value.
@@ -1284,11 +1284,11 @@ 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 {
-                       list[i] = &operand{mode: value, expr: e, typ: v.typ}
+                       list[i] = &operand{mode: value, expr: e, typ_: v.typ}
                }
                return
        }
@@ -1296,9 +1296,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) {
-               x2 := &operand{mode: value, expr: e, typ: Typ[UntypedBool]}
+               x2 := &operand{mode: value, expr: e, typ_: Typ[UntypedBool]}
                if x.mode == commaerr {
-                       x2.typ = universeError
+                       x2.typ_ = universeError
                }
                list = append(list, x2)
                commaOk = true
@@ -1359,7 +1359,7 @@ func (check *Checker) exclude(x *operand, modeset uint) {
 func (check *Checker) singleValue(x *operand) {
        if x.mode == value {
                // tuple types are never named - no need for underlying type below
-               if t, ok := x.typ.(*Tuple); ok {
+               if t, ok := x.typ_.(*Tuple); ok {
                        assert(t.Len() != 1)
                        check.errorf(x, TooManyValues, "multiple-value %s in single-value context", x)
                        x.mode = invalid
index 9089092e52be2d7024f2021bc6e486755462e059..a065eb19b0ffa64f241d480493d2a4464ef42293 100644 (file)
@@ -29,14 +29,14 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                // type instantiation
                x.mode = invalid
                // TODO(gri) here we re-evaluate e.X - try to avoid this
-               x.typ = check.varType(e.orig)
-               if isValid(x.typ) {
+               x.typ_ = check.varType(e.orig)
+               if isValid(x.typ_) {
                        x.mode = typexpr
                }
                return false
 
        case value:
-               if sig, _ := x.typ.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
+               if sig, _ := x.typ_.Underlying().(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
                        // function instantiation
                        return true
                }
@@ -49,11 +49,11 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
        }
 
        // We cannot index on an incomplete type; make sure it's complete.
-       if !check.isComplete(x.typ) {
+       if !check.isComplete(x.typ_) {
                x.mode = invalid
                return false
        }
-       switch typ := x.typ.Underlying().(type) {
+       switch typ := x.typ_.Underlying().(type) {
        case *Pointer:
                // Additionally, if x.typ is a pointer to an array type, indexing implicitly dereferences the value, meaning
                // its base type must also be complete.
@@ -73,7 +73,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
        // ordinary index expression
        valid := false
        length := int64(-1) // valid if >= 0
-       switch typ := x.typ.Underlying().(type) {
+       switch typ := x.typ_.Underlying().(type) {
        case *Basic:
                if isString(typ) {
                        valid = true
@@ -84,7 +84,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                        // (not a constant) even if the string and the
                        // index are constant
                        x.mode = value
-                       x.typ = universeByte // use 'byte' name
+                       x.typ_ = universeByte // use 'byte' name
                }
 
        case *Array:
@@ -93,20 +93,20 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                if x.mode != variable {
                        x.mode = value
                }
-               x.typ = typ.elem
+               x.typ_ = typ.elem
 
        case *Pointer:
                if typ, _ := typ.base.Underlying().(*Array); typ != nil {
                        valid = true
                        length = typ.len
                        x.mode = variable
-                       x.typ = typ.elem
+                       x.typ_ = typ.elem
                }
 
        case *Slice:
                valid = true
                x.mode = variable
-               x.typ = typ.elem
+               x.typ_ = typ.elem
 
        case *Map:
                index := check.singleIndex(e)
@@ -119,19 +119,19 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                check.assignment(&key, typ.key, "map index")
                // ok to continue even if indexing failed - map element type is known
                x.mode = mapindex
-               x.typ = typ.elem
+               x.typ_ = typ.elem
                x.expr = e.orig
                return false
 
        case *Interface:
-               if !isTypeParam(x.typ) {
+               if !isTypeParam(x.typ_) {
                        break
                }
                // TODO(gri) report detailed failure cause for better error messages
                var key, elem Type // key != nil: we must have all maps
                mode := variable   // non-maps result mode
                // TODO(gri) factor out closure and use it for non-typeparam cases as well
-               if underIs(x.typ, func(u Type) bool {
+               if underIs(x.typ_, func(u Type) bool {
                        l := int64(-1) // valid if >= 0
                        var k, e Type  // k is only set for maps
                        switch t := u.(type) {
@@ -193,7 +193,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                                check.assignment(&k, key, "map index")
                                // ok to continue even if indexing failed - map element type is known
                                x.mode = mapindex
-                               x.typ = elem
+                               x.typ_ = elem
                                x.expr = e.orig
                                return false
                        }
@@ -201,7 +201,7 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
                        // no maps
                        valid = true
                        x.mode = mode
-                       x.typ = elem
+                       x.typ_ = elem
                }
        }
 
@@ -222,8 +222,8 @@ func (check *Checker) indexExpr(x *operand, e *indexedExpr) (isFuncInst bool) {
        // In pathological (invalid) cases (e.g.: type T1 [][[]T1{}[0][0]]T0)
        // the element type may be accessed before it's set. Make sure we have
        // a valid type.
-       if x.typ == nil {
-               x.typ = Typ[Invalid]
+       if x.typ_ == nil {
+               x.typ_ = Typ[Invalid]
        }
 
        check.index(index, length)
@@ -241,9 +241,9 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
        var ct, cu Type // type and respective common underlying type
        var hasString bool
        // TODO(adonovan): use go1.23 "range typeset()".
-       typeset(x.typ)(func(t, u Type) bool {
+       typeset(x.typ_)(func(t, u Type) bool {
                if u == nil {
-                       check.errorf(x, NonSliceableOperand, "cannot slice %s: no specific type in %s", x, x.typ)
+                       check.errorf(x, NonSliceableOperand, "cannot slice %s: no specific type in %s", x, x.typ_)
                        cu = nil
                        return false
                }
@@ -273,15 +273,15 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
                // If we saw a string, proceed with string type,
                // but don't go from untyped string to string.
                cu = Typ[String]
-               if !isTypeParam(x.typ) {
-                       cu = x.typ.Underlying() // untyped string remains untyped
+               if !isTypeParam(x.typ_) {
+                       cu = x.typ_.Underlying() // untyped string remains untyped
                }
        }
 
        // Note that we don't permit slice expressions where x is a type expression, so we don't check for that here.
        // However, if x.typ is a pointer to an array type, slicing implicitly dereferences the value, meaning
        // its base type must also be complete.
-       if p, ok := x.typ.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
+       if p, ok := x.typ_.Underlying().(*Pointer); ok && !check.isComplete(p.base) {
                x.mode = invalid
                return
        }
@@ -311,8 +311,8 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
                        }
                        // spec: "For untyped string operands the result
                        // is a non-constant value of type string."
-                       if isUntyped(x.typ) {
-                               x.typ = Typ[String]
+                       if isUntyped(x.typ_) {
+                               x.typ_ = Typ[String]
                        }
                }
 
@@ -324,13 +324,13 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
                        x.mode = invalid
                        return
                }
-               x.typ = &Slice{elem: u.elem}
+               x.typ_ = &Slice{elem: u.elem}
 
        case *Pointer:
                if u, _ := u.base.Underlying().(*Array); u != nil {
                        valid = true
                        length = u.len
-                       x.typ = &Slice{elem: u.elem}
+                       x.typ_ = &Slice{elem: u.elem}
                }
 
        case *Slice:
@@ -428,7 +428,7 @@ func (check *Checker) index(index ast.Expr, max int64) (typ Type, val int64) {
        }
 
        if x.mode != constant_ {
-               return x.typ, -1
+               return x.typ_, -1
        }
 
        if x.val.Kind() == constant.Unknown {
@@ -443,7 +443,7 @@ func (check *Checker) index(index ast.Expr, max int64) (typ Type, val int64) {
        }
 
        // 0 <= v [ && v < max ]
-       return x.typ, v
+       return x.typ_, v
 }
 
 func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNegative bool) bool {
@@ -458,7 +458,7 @@ func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNega
        }
 
        // spec: "the index x must be of integer type or an untyped constant"
-       if !allInteger(x.typ) {
+       if !allInteger(x.typ_) {
                check.errorf(x, code, invalidArg+"%s %s must be integer", what, x)
                return false
        }
index 25a26b38a5eadf739bf97833d0ae9381668643bd..9f63c1f81171cf28020f06ae5b7ba9005b8b9904 100644 (file)
@@ -173,12 +173,12 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
                        continue
                }
                par := params.At(i)
-               if isParameterized(tparams, par.typ) || isParameterized(tparams, arg.typ) {
+               if isParameterized(tparams, par.typ) || isParameterized(tparams, arg.typ_) {
                        // Function parameters are always typed. Arguments may be untyped.
                        // Collect the indices of untyped arguments and handle them later.
-                       if isTyped(arg.typ) {
-                               if !u.unify(par.typ, arg.typ, assign) {
-                                       errorf(par.typ, arg.typ, arg)
+                       if isTyped(arg.typ_) {
+                               if !u.unify(par.typ, arg.typ_, assign) {
+                                       errorf(par.typ, arg.typ_, arg)
                                        return nil
                                }
                        } else if _, ok := par.typ.(*TypeParam); ok && !arg.isNil() {
@@ -340,11 +340,11 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
                        }
                        max := maxUntyped[tpar]
                        if max == nil {
-                               max = arg.typ
+                               max = arg.typ_
                        } else {
-                               m := maxType(max, arg.typ)
+                               m := maxType(max, arg.typ_)
                                if m == nil {
-                                       err.addf(arg, "mismatched types %s and %s (cannot infer %s)", max, arg.typ, tpar)
+                                       err.addf(arg, "mismatched types %s and %s (cannot infer %s)", max, arg.typ_, tpar)
                                        return nil
                                }
                                max = m
index 3bbb5d5cbd553fa5fd143aa7bddda23791ce4f44..cf230242ee1c35d730c18ec247316a9b26b6d137 100644 (file)
@@ -101,7 +101,7 @@ func (check *Checker) funcLit(x *operand, e *ast.FuncLit) {
                        }).describef(e, "func literal")
                }
                x.mode = value
-               x.typ = sig
+               x.typ_ = sig
        } else {
                check.errorf(e, InvalidSyntaxTree, "invalid function literal %v", e)
                x.mode = invalid
@@ -273,12 +273,12 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
                                xkey := keyVal(x.val)
                                if keyIsInterface {
                                        for _, vtyp := range visited[xkey] {
-                                               if Identical(vtyp, x.typ) {
+                                               if Identical(vtyp, x.typ_) {
                                                        duplicate = true
                                                        break
                                                }
                                        }
-                                       visited[xkey] = append(visited[xkey], x.typ)
+                                       visited[xkey] = append(visited[xkey], x.typ_)
                                } else {
                                        _, duplicate = visited[xkey]
                                        visited[xkey] = nil
@@ -321,7 +321,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
        }
 
        x.mode = value
-       x.typ = typ
+       x.typ_ = typ
 }
 
 // indexedElts checks the elements (elts) of an array or slice composite literal
index 9abeaafae0c4d260b88ea02af7f56b0081d5e760..330d9a42b6a1f6cff851eb901c16ead40e88e863 100644 (file)
@@ -59,7 +59,7 @@ var operandModeString = [...]string{
 type operand struct {
        mode operandMode
        expr ast.Expr
-       typ  Type
+       typ_ Type
        val  constant.Value
        id   builtinId
 }
@@ -114,17 +114,17 @@ func operandString(x *operand, qf Qualifier) string {
        // special-case nil
        if isTypes2 {
                if x.mode == nilvalue {
-                       switch x.typ {
+                       switch x.typ_ {
                        case nil, Typ[Invalid]:
                                return "nil (with invalid type)"
                        case Typ[UntypedNil]:
                                return "nil"
                        default:
-                               return fmt.Sprintf("nil (of type %s)", TypeString(x.typ, qf))
+                               return fmt.Sprintf("nil (of type %s)", TypeString(x.typ_, qf))
                        }
                }
        } else { // go/types
-               if x.mode == value && x.typ == Typ[UntypedNil] {
+               if x.mode == value && x.typ_ == Typ[UntypedNil] {
                        return "nil"
                }
        }
@@ -139,7 +139,7 @@ func operandString(x *operand, qf Qualifier) string {
                case builtin:
                        expr = predeclaredFuncs[x.id].name
                case typexpr:
-                       expr = TypeString(x.typ, qf)
+                       expr = TypeString(x.typ_, qf)
                case constant_:
                        expr = x.val.String()
                }
@@ -158,9 +158,9 @@ func operandString(x *operand, qf Qualifier) string {
                // no type
        default:
                // should have a type, but be cautious (don't crash during printing)
-               if x.typ != nil {
-                       if isUntyped(x.typ) {
-                               buf.WriteString(x.typ.(*Basic).name)
+               if x.typ_ != nil {
+                       if isUntyped(x.typ_) {
+                               buf.WriteString(x.typ_.(*Basic).name)
                                buf.WriteByte(' ')
                                break
                        }
@@ -181,9 +181,9 @@ func operandString(x *operand, qf Qualifier) string {
 
        // <typ>
        if hasType {
-               if isValid(x.typ) {
+               if isValid(x.typ_) {
                        var desc string
-                       if isGeneric(x.typ) {
+                       if isGeneric(x.typ_) {
                                desc = "generic "
                        }
 
@@ -191,14 +191,14 @@ func operandString(x *operand, qf Qualifier) string {
                        // If the type is a renamed basic type, describe the basic type,
                        // as in "int32 type MyInt" for a *Named type MyInt.
                        // If it is a type parameter, describe the constraint instead.
-                       tpar, _ := Unalias(x.typ).(*TypeParam)
+                       tpar, _ := Unalias(x.typ_).(*TypeParam)
                        if tpar == nil {
-                               switch x.typ.(type) {
+                               switch x.typ_.(type) {
                                case *Alias, *Named:
-                                       what := compositeKind(x.typ)
+                                       what := compositeKind(x.typ_)
                                        if what == "" {
                                                // x.typ must be basic type
-                                               what = x.typ.Underlying().(*Basic).name
+                                               what = x.typ_.Underlying().(*Basic).name
                                        }
                                        desc += what + " "
                                }
@@ -206,7 +206,7 @@ func operandString(x *operand, qf Qualifier) string {
                        // desc is "" or has a trailing space at the end
 
                        buf.WriteString(" of " + desc + "type ")
-                       WriteType(&buf, x.typ, qf)
+                       WriteType(&buf, x.typ_, qf)
 
                        if tpar != nil {
                                buf.WriteString(" constrained by ")
@@ -286,11 +286,11 @@ func (x *operand) setConst(k token.Token, lit string) {
        val := makeFromLiteral(lit, k)
        if val.Kind() == constant.Unknown {
                x.mode = invalid
-               x.typ = Typ[Invalid]
+               x.typ_ = Typ[Invalid]
                return
        }
        x.mode = constant_
-       x.typ = Typ[kind]
+       x.typ_ = Typ[kind]
        x.val = val
 }
 
@@ -299,7 +299,7 @@ func (x *operand) isNil() bool {
        if isTypes2 {
                return x.mode == nilvalue
        } else { // go/types
-               return x.mode == value && x.typ == Typ[UntypedNil]
+               return x.mode == value && x.typ_ == Typ[UntypedNil]
        }
 }
 
@@ -315,7 +315,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
        }
 
        origT := T
-       V := Unalias(x.typ)
+       V := Unalias(x.typ_)
        T = Unalias(T)
 
        // x's type is identical to T
@@ -420,7 +420,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
                        }
                        ok, code = x.assignableTo(check, T.typ, cause)
                        if !ok {
-                               errorf("cannot assign %s to %s (in %s)", x.typ, T.typ, Tp)
+                               errorf("cannot assign %s to %s (in %s)", x.typ_, T.typ, Tp)
                                return false
                        }
                        return true
@@ -439,7 +439,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
                        if V == nil {
                                return false // no specific types
                        }
-                       x.typ = V.typ
+                       x.typ_ = V.typ
                        ok, code = x.assignableTo(check, T, cause)
                        if !ok {
                                errorf("cannot assign %s (in %s) to %s", V.typ, Vp, origT)
index d38150dea774804da26f9a0b45a9ea43bbe4c84c..2d160326432cf198af90d06a72d59d5e2d43b071 100644 (file)
@@ -38,7 +38,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
        check.expr(nil, &x, rangeVar)
 
        if isTypes2 && x.mode != invalid && sValue == nil && !check.hasCallOrRecv {
-               if t, ok := arrayPtrDeref(x.typ.Underlying()).(*Array); ok {
+               if t, ok := arrayPtrDeref(x.typ_.Underlying()).(*Array); ok {
                        for {
                                // Put constant info on the thing inside parentheses.
                                // That's where (*../noder/writer).expr expects it.
@@ -55,7 +55,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
                        check.record(&operand{
                                mode: constant_,
                                expr: rangeVar,
-                               typ Typ[Int],
+                               typ_: Typ[Int],
                                val:  constant.MakeInt64(t.len),
                                id:   x.id,
                        })
@@ -65,7 +65,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
        // determine key/value types
        var key, val Type
        if x.mode != invalid {
-               k, v, cause, ok := rangeKeyVal(check, x.typ, func(v goVersion) bool {
+               k, v, cause, ok := rangeKeyVal(check, x.typ_, func(v goVersion) bool {
                        return check.allowVersion(v)
                })
                switch {
@@ -95,7 +95,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
        lhs := [2]ast.Expr{sKey, sValue} // sKey, sValue may be nil
        rhs := [2]Type{key, val}         // key, val may be nil
 
-       rangeOverInt := isInteger(x.typ)
+       rangeOverInt := isInteger(x.typ_)
 
        if isDef {
                // short variable declaration
@@ -138,7 +138,7 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
                                var y operand
                                y.mode = value
                                y.expr = lhs // we don't have a better rhs expression to use here
-                               y.typ = typ
+                               y.typ_ = typ
                                check.initVar(obj, &y, "assignment") // error is on variable, use "assignment" not "range clause"
                        }
                        assert(obj.typ != nil)
@@ -172,14 +172,14 @@ 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) {
-                                       check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ)
+                               if x.mode != invalid && !isInteger(x.typ_) {
+                                       check.softErrorf(lhs, InvalidRangeExpr, "cannot use iteration variable of type %s", x.typ_)
                                }
                        } else {
                                var y operand
                                y.mode = value
                                y.expr = lhs // we don't have a better rhs expression to use here
-                               y.typ = typ
+                               y.typ_ = typ
                                check.assignVar(lhs, nil, &y, "assignment") // error is on variable, use "assignment" not "range clause"
                        }
                }
index c6da3357b550ace45d8a3bc646a72b89547bb383..5709ce980a93c102069a9caae6684f257611bdd9 100644 (file)
@@ -26,10 +26,10 @@ func (check *Checker) record(x *operand) {
        case novalue:
                typ = (*Tuple)(nil)
        case constant_:
-               typ = x.typ
+               typ = x.typ_
                val = x.val
        default:
-               typ = x.typ
+               typ = x.typ_
        }
        assert(x.expr != nil && typ != nil)
 
@@ -100,7 +100,7 @@ func (check *Checker) recordCommaOkTypes(x ast.Expr, a []*operand) {
        if a[0].mode == invalid {
                return
        }
-       t0, t1 := a[0].typ, a[1].typ
+       t0, t1 := a[0].typ_, a[1].typ_
        assert(isTyped(t0) && isTyped(t1) && (allBoolean(t1) || t1 == universeError))
        if m := check.Types; m != nil {
                for {
index 398075eaf3730095ce3f3c58fe869d296edc094d..bc97c8ed45d16f86d0bbcb631d13f73c0cf43ea5 100644 (file)
@@ -242,7 +242,7 @@ L:
                if x.mode == invalid || v.mode == invalid {
                        continue L
                }
-               check.convertUntyped(&v, x.typ)
+               check.convertUntyped(&v, x.typ_)
                if v.mode == invalid {
                        continue L
                }
@@ -260,7 +260,7 @@ L:
                        // look for duplicate types for a given value
                        // (quadratic algorithm, but these lists tend to be very short)
                        for _, vt := range seen[val] {
-                               if Identical(v.typ, vt.typ) {
+                               if Identical(v.typ_, vt.typ) {
                                        err := check.newError(DuplicateCase)
                                        err.addf(&v, "duplicate case %s in expression switch", &v)
                                        err.addf(atPos(vt.pos), "previous case")
@@ -268,7 +268,7 @@ L:
                                        continue L
                                }
                        }
-                       seen[val] = append(seen[val], valueType{v.Pos(), v.typ})
+                       seen[val] = append(seen[val], valueType{v.Pos(), v.typ_})
                }
        }
 }
@@ -346,7 +346,7 @@ L:
        if len(types) != 1 || T == nil {
                T = Typ[Invalid]
                if x != nil {
-                       T = x.typ
+                       T = x.typ_
                }
        }
 
@@ -399,7 +399,7 @@ L:
        if len(types) != 1 || T == nil {
                T = Typ[Invalid]
                if x != nil {
-                       T = x.typ
+                       T = x.typ_
                }
        }
 
@@ -489,8 +489,8 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                if x.mode == invalid {
                        return
                }
-               if !allNumeric(x.typ) {
-                       check.errorf(s.X, NonNumericIncDec, invalidOp+"%s%s (non-numeric type %s)", s.X, s.Tok, x.typ)
+               if !allNumeric(x.typ_) {
+                       check.errorf(s.X, NonNumericIncDec, invalidOp+"%s%s (non-numeric type %s)", s.X, s.Tok, x.typ_)
                        return
                }
 
@@ -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,15 +636,15 @@ 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) {
-                               check.errorf(&x, InvalidExprSwitch, "cannot switch on %s (%s is not comparable)", &x, 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
                        }
                } else {
                        // spec: "A missing switch expression is
                        // equivalent to the boolean value true."
                        x.mode = constant_
-                       x.typ = Typ[Bool]
+                       x.typ_ = Typ[Bool]
                        x.val = constant.MakeBool(true)
                        x.expr = &ast.Ident{NamePos: s.Body.Lbrace, Name: "true"}
                }
@@ -729,9 +729,9 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                        var x operand
                        check.expr(nil, &x, expr.X)
                        if x.mode != invalid {
-                               if isTypeParam(x.typ) {
+                               if isTypeParam(x.typ_) {
                                        check.errorf(&x, InvalidTypeSwitch, "cannot use type switch on type parameter value %s", &x)
-                               } else if IsInterface(x.typ) {
+                               } else if IsInterface(x.typ_) {
                                        sx = &x
                                } else {
                                        check.errorf(&x, InvalidTypeSwitch, "%s is not an interface", &x)
@@ -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 7b9d2d3cbc4b5beecaf4a555b98877385f04d66f..0fed2f65979faeec5f957a6e0f153ec240610b6e 100644 (file)
@@ -131,7 +131,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, wantType bool) {
                panic("unreachable")
        }
 
-       x.typ = typ
+       x.typ_ = typ
 }
 
 // typ type-checks the type expression e and returns its type, or Typ[Invalid].
@@ -248,7 +248,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *TypeName) (T Type) {
 
                switch x.mode {
                case typexpr:
-                       return x.typ
+                       return x.typ_
                case invalid:
                        // ignore - error reported before
                case novalue:
@@ -263,7 +263,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *TypeName) (T Type) {
 
                switch x.mode {
                case typexpr:
-                       return x.typ
+                       return x.typ_
                case invalid:
                        // ignore - error reported before
                case novalue:
@@ -485,7 +485,7 @@ func (check *Checker) arrayLength(e ast.Expr) int64 {
                return -1
        }
 
-       if isUntyped(x.typ) || isInteger(x.typ) {
+       if isUntyped(x.typ_) || isInteger(x.typ_) {
                if val := constant.ToInt(x.val); val.Kind() == constant.Int {
                        if representableConst(val, check, Typ[Int], nil) {
                                if n, ok := constant.Int64Val(val); ok && n >= 0 {
@@ -496,7 +496,7 @@ func (check *Checker) arrayLength(e ast.Expr) int64 {
        }
 
        var msg string
-       if isInteger(x.typ) {
+       if isInteger(x.typ_) {
                msg = "invalid array length %s"
        } else {
                msg = "array length %s must be integer"