// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This file implements typechecking of expressions.

package types

import (
	
	
	
	
	
	
)

/*
Basic algorithm:

Expressions are checked recursively, top down. Expression checker functions
are generally of the form:

  func f(x *operand, e *ast.Expr, ...)

where e is the expression to be checked, and x is the result of the check.
The check performed by f may fail in which case x.mode == invalid, and
related error messages will have been issued by f.

If a hint argument is present, it is the composite literal element type
of an outer composite literal; it is used to type-check composite literal
elements that have no explicit type specification in the source
(e.g.: []T{{...}, {...}}, the hint is the type T in this case).

All expressions are checked via rawExpr, which dispatches according
to expression kind. Upon returning, rawExpr is recording the types and
constant values for all expressions that have an untyped type (those types
may change on the way up in the expression tree). Usually these are constants,
but the results of comparisons or non-constant shifts of untyped constants
may also be untyped, but not constant.

Untyped expressions may eventually become fully typed (i.e., not untyped),
typically when the value is assigned to a variable, or is used otherwise.
The updateExprType method is used to record this final type and update
the recorded types: the type-checked expression tree is again traversed down,
and the new type is propagated as needed. Untyped constant expression values
that become fully typed must now be representable by the full type (constant
sub-expression trees are left alone except for their roots). This mechanism
ensures that a client sees the actual (run-time) type an untyped value would
have. It also permits type-checking of lhs shift operands "as if the shift
were not present": when updateExprType visits an untyped lhs shift operand
and assigns it it's final type, that type must be an integer type, and a
constant lhs must be representable as an integer.

When an expression gets its final type, either on the way out from rawExpr,
on the way down in updateExprType, or at the end of the type checker run,
the type (and constant value, if any) is recorded via Info.Types, if present.
*/

type opPredicates map[token.Token]func(Type) bool

var unaryOpPredicates opPredicates

func init() {
	// Setting unaryOpPredicates in init avoids declaration cycles.
	unaryOpPredicates = opPredicates{
		token.ADD: allNumeric,
		token.SUB: allNumeric,
		token.XOR: allInteger,
		token.NOT: allBoolean,
	}
}

func ( *Checker) ( opPredicates,  *operand,  token.Token) bool {
	if  := [];  != nil {
		if !(.typ) {
			.invalidOp(, _UndefinedOp, "operator %s not defined on %s", , )
			return false
		}
	} else {
		.invalidAST(, "unknown operator %s", )
		return false
	}
	return true
}

// overflow checks that the constant x is representable by its type.
// For untyped constants, it checks that the value doesn't become
// arbitrarily large.
func ( *Checker) ( *operand,  token.Token,  token.Pos) {
	assert(.mode == constant_)

	if .val.Kind() == constant.Unknown {
		// TODO(gri) We should report exactly what went wrong. At the
		//           moment we don't have the (go/constant) API for that.
		//           See also TODO in go/constant/value.go.
		.errorf(atPos(), _InvalidConstVal, "constant result is not representable")
		return
	}

	// Typed constants must be representable in
	// their type after each constant operation.
	// x.typ cannot be a type parameter (type
	// parameters cannot be constant types).
	if isTyped(.typ) {
		.representable(, under(.typ).(*Basic))
		return
	}

	// Untyped integer values must not grow arbitrarily.
	const  = 512 // 512 is the constant precision
	if .val.Kind() == constant.Int && constant.BitLen(.val) >  {
		.errorf(atPos(), _InvalidConstVal, "constant %s overflow", opName(.expr))
		.val = constant.MakeUnknown()
	}
}

// opName returns the name of an operation, or the empty string.
// Only operations that might overflow are handled.
func opName( ast.Expr) string {
	switch e := .(type) {
	case *ast.BinaryExpr:
		if int(.Op) < len(op2str2) {
			return op2str2[.Op]
		}
	case *ast.UnaryExpr:
		if int(.Op) < len(op2str1) {
			return op2str1[.Op]
		}
	}
	return ""
}

var op2str1 = [...]string{
	token.XOR: "bitwise complement",
}

// This is only used for operations that may cause overflow.
var op2str2 = [...]string{
	token.ADD: "addition",
	token.SUB: "subtraction",
	token.XOR: "bitwise XOR",
	token.MUL: "multiplication",
	token.SHL: "shift",
}

// If typ is a type parameter, underIs returns the result of typ.underIs(f).
// Otherwise, underIs returns the result of f(under(typ)).
func underIs( Type,  func(Type) bool) bool {
	if ,  := .(*TypeParam);  != nil {
		return .underIs()
	}
	return (under())
}

// The unary expression e may be nil. It's passed in for better error messages only.
func ( *Checker) ( *operand,  *ast.UnaryExpr) {
	.expr(, .X)
	if .mode == invalid {
		return
	}
	switch .Op {
	case token.AND:
		// spec: "As an exception to the addressability
		// requirement x may also be a composite literal."
		if ,  := unparen(.X).(*ast.CompositeLit); ! && .mode != variable {
			.invalidOp(, _UnaddressableOperand, "cannot take address of %s", )
			.mode = invalid
			return
		}
		.mode = value
		.typ = &Pointer{base: .typ}
		return

	case token.ARROW:
		 := coreType(.typ)
		if  == nil {
			.invalidOp(, _InvalidReceive, "cannot receive from %s: no core type", )
			.mode = invalid
			return
		}
		,  := .(*Chan)
		if  == nil {
			.invalidOp(, _InvalidReceive, "cannot receive from non-channel %s", )
			.mode = invalid
			return
		}
		if .dir == SendOnly {
			.invalidOp(, _InvalidReceive, "cannot receive from send-only channel %s", )
			.mode = invalid
			return
		}

		.mode = commaok
		.typ = .elem
		.hasCallOrRecv = true
		return
	}

	if !.op(unaryOpPredicates, , .Op) {
		.mode = invalid
		return
	}

	if .mode == constant_ {
		if .val.Kind() == constant.Unknown {
			// nothing to do (and don't cause an error below in the overflow check)
			return
		}
		var  uint
		if isUnsigned(.typ) {
			 = uint(.conf.sizeof(.typ) * 8)
		}
		.val = constant.UnaryOp(.Op, .val, )
		.expr = 
		.overflow(, .Op, .Pos())
		return
	}

	.mode = value
	// x.typ remains unchanged
}

func isShift( token.Token) bool {
	return  == token.SHL ||  == token.SHR
}

func isComparison( token.Token) bool {
	// Note: tokens are not ordered well to make this much easier
	switch  {
	case token.EQL, token.NEQ, token.LSS, token.LEQ, token.GTR, token.GEQ:
		return true
	}
	return false
}

func fitsFloat32( constant.Value) bool {
	,  := constant.Float32Val()
	 := float64()
	return !math.IsInf(, 0)
}

func roundFloat32( constant.Value) constant.Value {
	,  := constant.Float32Val()
	 := float64()
	if !math.IsInf(, 0) {
		return constant.MakeFloat64()
	}
	return nil
}

func fitsFloat64( constant.Value) bool {
	,  := constant.Float64Val()
	return !math.IsInf(, 0)
}

func roundFloat64( constant.Value) constant.Value {
	,  := constant.Float64Val()
	if !math.IsInf(, 0) {
		return constant.MakeFloat64()
	}
	return nil
}

// representableConst reports whether x can be represented as
// value of the given basic type and for the configuration
// provided (only needed for int/uint sizes).
//
// If rounded != nil, *rounded is set to the rounded value of x for
// representable floating-point and complex values, and to an Int
// value for integer values; it is left alone otherwise.
// It is ok to provide the addressof the first argument for rounded.
//
// The check parameter may be nil if representableConst is invoked
// (indirectly) through an exported API call (AssignableTo, ConvertibleTo)
// because we don't need the Checker's config for those calls.
func representableConst( constant.Value,  *Checker,  *Basic,  *constant.Value) bool {
	if .Kind() == constant.Unknown {
		return true // avoid follow-up errors
	}

	var  *Config
	if  != nil {
		 = .conf
	}

	switch {
	case isInteger():
		 := constant.ToInt()
		if .Kind() != constant.Int {
			return false
		}
		if  != nil {
			* = 
		}
		if ,  := constant.Int64Val();  {
			switch .kind {
			case Int:
				var  = uint(.sizeof()) * 8
				return int64(-1)<<(-1) <=  &&  <= int64(1)<<(-1)-1
			case Int8:
				const  = 8
				return -1<<(-1) <=  &&  <= 1<<(-1)-1
			case Int16:
				const  = 16
				return -1<<(-1) <=  &&  <= 1<<(-1)-1
			case Int32:
				const  = 32
				return -1<<(-1) <=  &&  <= 1<<(-1)-1
			case Int64, UntypedInt:
				return true
			case Uint, Uintptr:
				if  := uint(.sizeof()) * 8;  < 64 {
					return 0 <=  &&  <= int64(1)<<-1
				}
				return 0 <= 
			case Uint8:
				const  = 8
				return 0 <=  &&  <= 1<<-1
			case Uint16:
				const  = 16
				return 0 <=  &&  <= 1<<-1
			case Uint32:
				const  = 32
				return 0 <=  &&  <= 1<<-1
			case Uint64:
				return 0 <= 
			default:
				unreachable()
			}
		}
		// x does not fit into int64
		switch  := constant.BitLen(); .kind {
		case Uint, Uintptr:
			var  = uint(.sizeof()) * 8
			return constant.Sign() >= 0 &&  <= int()
		case Uint64:
			return constant.Sign() >= 0 &&  <= 64
		case UntypedInt:
			return true
		}

	case isFloat():
		 := constant.ToFloat()
		if .Kind() != constant.Float {
			return false
		}
		switch .kind {
		case Float32:
			if  == nil {
				return fitsFloat32()
			}
			 := roundFloat32()
			if  != nil {
				* = 
				return true
			}
		case Float64:
			if  == nil {
				return fitsFloat64()
			}
			 := roundFloat64()
			if  != nil {
				* = 
				return true
			}
		case UntypedFloat:
			return true
		default:
			unreachable()
		}

	case isComplex():
		 := constant.ToComplex()
		if .Kind() != constant.Complex {
			return false
		}
		switch .kind {
		case Complex64:
			if  == nil {
				return fitsFloat32(constant.Real()) && fitsFloat32(constant.Imag())
			}
			 := roundFloat32(constant.Real())
			 := roundFloat32(constant.Imag())
			if  != nil &&  != nil {
				* = constant.BinaryOp(, token.ADD, constant.MakeImag())
				return true
			}
		case Complex128:
			if  == nil {
				return fitsFloat64(constant.Real()) && fitsFloat64(constant.Imag())
			}
			 := roundFloat64(constant.Real())
			 := roundFloat64(constant.Imag())
			if  != nil &&  != nil {
				* = constant.BinaryOp(, token.ADD, constant.MakeImag())
				return true
			}
		case UntypedComplex:
			return true
		default:
			unreachable()
		}

	case isString():
		return .Kind() == constant.String

	case isBoolean():
		return .Kind() == constant.Bool
	}

	return false
}

// representable checks that a constant operand is representable in the given
// basic type.
func ( *Checker) ( *operand,  *Basic) {
	,  := .representation(, )
	if  != 0 {
		.invalidConversion(, , )
		.mode = invalid
		return
	}
	assert( != nil)
	.val = 
}

// representation returns the representation of the constant operand x as the
// basic type typ.
//
// If no such representation is possible, it returns a non-zero error code.
func ( *Checker) ( *operand,  *Basic) (constant.Value, errorCode) {
	assert(.mode == constant_)
	 := .val
	if !representableConst(.val, , , &) {
		if isNumeric(.typ) && isNumeric() {
			// numeric conversion : error msg
			//
			// integer -> integer : overflows
			// integer -> float   : overflows (actually not possible)
			// float   -> integer : truncated
			// float   -> float   : overflows
			//
			if !isInteger(.typ) && isInteger() {
				return nil, _TruncatedFloat
			} else {
				return nil, _NumericOverflow
			}
		}
		return nil, _InvalidConstVal
	}
	return , 0
}

func ( *Checker) ( errorCode,  *operand,  Type) {
	 := "cannot convert %s to %s"
	switch  {
	case _TruncatedFloat:
		 = "%s truncated to %s"
	case _NumericOverflow:
		 = "%s overflows %s"
	}
	.errorf(, , , , )
}

// updateExprType updates the type of x to typ and invokes itself
// recursively for the operands of x, depending on expression kind.
// If typ is still an untyped and not the final type, updateExprType
// only updates the recorded untyped type for x and possibly its
// operands. Otherwise (i.e., typ is not an untyped type anymore,
// or it is the final type for x), the type and value are recorded.
// Also, if x is a constant, it must be representable as a value of typ,
// and if x is the (formerly untyped) lhs operand of a non-constant
// shift, it must be an integer value.
func ( *Checker) ( ast.Expr,  Type,  bool) {
	.updateExprType0(nil, , , )
}

func ( *Checker) (,  ast.Expr,  Type,  bool) {
	,  := .untyped[]
	if ! {
		return // nothing to do
	}

	// update operands of x if necessary
	switch x := .(type) {
	case *ast.BadExpr,
		*ast.FuncLit,
		*ast.CompositeLit,
		*ast.IndexExpr,
		*ast.SliceExpr,
		*ast.TypeAssertExpr,
		*ast.StarExpr,
		*ast.KeyValueExpr,
		*ast.ArrayType,
		*ast.StructType,
		*ast.FuncType,
		*ast.InterfaceType,
		*ast.MapType,
		*ast.ChanType:
		// These expression are never untyped - nothing to do.
		// The respective sub-expressions got their final types
		// upon assignment or use.
		if debug {
			.dump("%v: found old type(%s): %s (new: %s)", .Pos(), , .typ, )
			unreachable()
		}
		return

	case *ast.CallExpr:
		// Resulting in an untyped constant (e.g., built-in complex).
		// The respective calls take care of calling updateExprType
		// for the arguments if necessary.

	case *ast.Ident, *ast.BasicLit, *ast.SelectorExpr:
		// An identifier denoting a constant, a constant literal,
		// or a qualified identifier (imported untyped constant).
		// No operands to take care of.

	case *ast.ParenExpr:
		.(, .X, , )

	case *ast.UnaryExpr:
		// If x is a constant, the operands were constants.
		// The operands don't need to be updated since they
		// never get "materialized" into a typed value. If
		// left in the untyped map, they will be processed
		// at the end of the type check.
		if .val != nil {
			break
		}
		.(, .X, , )

	case *ast.BinaryExpr:
		if .val != nil {
			break // see comment for unary expressions
		}
		if isComparison(.Op) {
			// The result type is independent of operand types
			// and the operand types must have final types.
		} else if isShift(.Op) {
			// The result type depends only on lhs operand.
			// The rhs type was updated when checking the shift.
			.(, .X, , )
		} else {
			// The operand types match the result type.
			.(, .X, , )
			.(, .Y, , )
		}

	default:
		unreachable()
	}

	// If the new type is not final and still untyped, just
	// update the recorded type.
	if ! && isUntyped() {
		.typ = under().(*Basic)
		.untyped[] = 
		return
	}

	// Otherwise we have the final (typed or untyped type).
	// Remove it from the map of yet untyped expressions.
	delete(.untyped, )

	if .isLhs {
		// If x is the lhs of a shift, its final type must be integer.
		// We already know from the shift check that it is representable
		// as an integer if it is a constant.
		if !allInteger() {
			if compilerErrorMessages {
				.invalidOp(, _InvalidShiftOperand, "%s (shift of type %s)", , )
			} else {
				.invalidOp(, _InvalidShiftOperand, "shifted operand %s (type %s) must be integer", , )
			}
			return
		}
		// Even if we have an integer, if the value is a constant we
		// still must check that it is representable as the specific
		// int type requested (was issue #22969). Fall through here.
	}
	if .val != nil {
		// If x is a constant, it must be representable as a value of typ.
		 := operand{.mode, , .typ, .val, 0}
		.convertUntyped(&, )
		if .mode == invalid {
			return
		}
	}

	// Everything's fine, record final type and value for x.
	.recordTypeAndValue(, .mode, , .val)
}

// updateExprVal updates the value of x to val.
func ( *Checker) ( ast.Expr,  constant.Value) {
	if ,  := .untyped[];  {
		.val = 
		.untyped[] = 
	}
}

// convertUntyped attempts to set the type of an untyped value to the target type.
func ( *Checker) ( *operand,  Type) {
	, ,  := .implicitTypeAndValue(, )
	if  != 0 {
		 := 
		if !isTypeParam() {
			 = safeUnderlying()
		}
		.invalidConversion(, , )
		.mode = invalid
		return
	}
	if  != nil {
		.val = 
		.updateExprVal(.expr, )
	}
	if  != .typ {
		.typ = 
		.updateExprType(.expr, , false)
	}
}

// implicitTypeAndValue returns the implicit type of x when used in a context
// where the target type is expected. If no such implicit conversion is
// possible, it returns a nil Type and non-zero error code.
//
// If x is a constant operand, the returned constant.Value will be the
// representation of x in this context.
func ( *Checker) ( *operand,  Type) (Type, constant.Value, errorCode) {
	if .mode == invalid || isTyped(.typ) ||  == Typ[Invalid] {
		return .typ, nil, 0
	}

	if isUntyped() {
		// both x and target are untyped
		 := .typ.(*Basic).kind
		 := .(*Basic).kind
		if isNumeric(.typ) && isNumeric() {
			if  <  {
				return , nil, 0
			}
		} else if  !=  {
			return nil, nil, _InvalidUntypedConversion
		}
		return .typ, nil, 0
	}

	switch u := under().(type) {
	case *Basic:
		if .mode == constant_ {
			,  := .representation(, )
			if  != 0 {
				return nil, nil, 
			}
			return , , 
		}
		// Non-constant untyped values may appear as the
		// result of comparisons (untyped bool), intermediate
		// (delayed-checked) rhs operands of shifts, and as
		// the value nil.
		switch .typ.(*Basic).kind {
		case UntypedBool:
			if !isBoolean() {
				return nil, nil, _InvalidUntypedConversion
			}
		case UntypedInt, UntypedRune, UntypedFloat, UntypedComplex:
			if !isNumeric() {
				return nil, nil, _InvalidUntypedConversion
			}
		case UntypedString:
			// Non-constant untyped string values are not permitted by the spec and
			// should not occur during normal typechecking passes, but this path is
			// reachable via the AssignableTo API.
			if !isString() {
				return nil, nil, _InvalidUntypedConversion
			}
		case UntypedNil:
			// Unsafe.Pointer is a basic type that includes nil.
			if !hasNil() {
				return nil, nil, _InvalidUntypedConversion
			}
			// Preserve the type of nil as UntypedNil: see #13061.
			return Typ[UntypedNil], nil, 0
		default:
			return nil, nil, _InvalidUntypedConversion
		}
	case *Interface:
		if isTypeParam() {
			if !.typeSet().underIs(func( Type) bool {
				if  == nil {
					return false
				}
				, ,  := .(, )
				return  != nil
			}) {
				return nil, nil, _InvalidUntypedConversion
			}
			// keep nil untyped (was bug #39755)
			if .isNil() {
				return Typ[UntypedNil], nil, 0
			}
			break
		}
		// Values must have concrete dynamic types. If the value is nil,
		// keep it untyped (this is important for tools such as go vet which
		// need the dynamic type for argument checking of say, print
		// functions)
		if .isNil() {
			return Typ[UntypedNil], nil, 0
		}
		// cannot assign untyped values to non-empty interfaces
		if !.Empty() {
			return nil, nil, _InvalidUntypedConversion
		}
		return Default(.typ), nil, 0
	case *Pointer, *Signature, *Slice, *Map, *Chan:
		if !.isNil() {
			return nil, nil, _InvalidUntypedConversion
		}
		// Keep nil untyped - see comment for interfaces, above.
		return Typ[UntypedNil], nil, 0
	default:
		return nil, nil, _InvalidUntypedConversion
	}
	return , nil, 0
}

// If switchCase is true, the operator op is ignored.
func ( *Checker) (,  *operand,  token.Token,  bool) {
	if  {
		 = token.EQL
	}

	 :=   // operand for which error is reported, if any
	 := "" // specific error cause, if any

	// spec: "In any comparison, the first operand must be assignable
	// to the type of the second operand, or vice versa."
	 := _MismatchedTypes
	,  := .assignableTo(, .typ, nil)
	if ! {
		, _ = .assignableTo(, .typ, nil)
	}
	if ! {
		// Report the error on the 2nd operand since we only
		// know after seeing the 2nd operand whether we have
		// a type mismatch.
		 = 
		// For now, if we're not running the compiler, use the
		// position of x to minimize changes to existing tests.
		if !compilerErrorMessages {
			 = 
		}
		 = .sprintf("mismatched types %s and %s", .typ, .typ)
		goto 
	}

	// check if comparison is defined for operands
	 = _UndefinedOp
	switch  {
	case token.EQL, token.NEQ:
		// spec: "The equality operators == and != apply to operands that are comparable."
		switch {
		case .isNil() || .isNil():
			// Comparison against nil requires that the other operand type has nil.
			 := .typ
			if .isNil() {
				 = .typ
			}
			if !hasNil() {
				// This case should only be possible for "nil == nil".
				// Report the error on the 2nd operand since we only
				// know after seeing the 2nd operand whether we have
				// an invalid comparison.
				 = 
				goto 
			}

		case !Comparable(.typ):
			 = 
			 = .incomparableCause(.typ)
			goto 

		case !Comparable(.typ):
			 = 
			 = .incomparableCause(.typ)
			goto 
		}

	case token.LSS, token.LEQ, token.GTR, token.GEQ:
		// spec: The ordering operators <, <=, >, and >= apply to operands that are ordered."
		switch {
		case !allOrdered(.typ):
			 = 
			goto 
		case !allOrdered(.typ):
			 = 
			goto 
		}

	default:
		unreachable()
	}

	// comparison is ok
	if .mode == constant_ && .mode == constant_ {
		.val = constant.MakeBool(constant.Compare(.val, , .val))
		// The operands are never materialized; no need to update
		// their types.
	} else {
		.mode = value
		// The operands have now their final types, which at run-
		// time will be materialized. Update the expression trees.
		// If the current types are untyped, the materialized type
		// is the respective default type.
		.updateExprType(.expr, Default(.typ), true)
		.updateExprType(.expr, Default(.typ), true)
	}

	// spec: "Comparison operators compare two operands and yield
	//        an untyped boolean value."
	.typ = Typ[UntypedBool]
	return

:
	// We have an offending operand errOp and possibly an error cause.
	if  == "" {
		if isTypeParam(.typ) || isTypeParam(.typ) {
			// TODO(gri) should report the specific type causing the problem, if any
			if !isTypeParam(.typ) {
				 = 
			}
			 = .sprintf("type parameter %s is not comparable with %s", .typ, )
		} else {
			 = .sprintf("operator %s not defined on %s", , .kindString(.typ)) // catch-all
		}
	}
	if  {
		.errorf(, , "invalid case %s in switch on %s (%s)", .expr, .expr, ) // error position always at 1st operand
	} else {
		if compilerErrorMessages {
			.invalidOp(, , "%s %s %s (%s)", .expr, , .expr, )
		} else {
			.invalidOp(, , "cannot compare %s %s %s (%s)", .expr, , .expr, )
		}
	}
	.mode = invalid
}

// incomparableCause returns a more specific cause why typ is not comparable.
// If there is no more specific cause, the result is "".
func ( *Checker) ( Type) string {
	switch under().(type) {
	case *Slice, *Signature, *Map:
		return .kindString() + " can only be compared to nil"
	}
	// see if we can extract a more specific error
	var  string
	comparable(, true, nil, func( string,  ...interface{}) {
		 = .sprintf(, ...)
	})
	return 
}

// kindString returns the type kind as a string.
func ( *Checker) ( Type) string {
	switch under().(type) {
	case *Array:
		return "array"
	case *Slice:
		return "slice"
	case *Struct:
		return "struct"
	case *Pointer:
		return "pointer"
	case *Signature:
		return "func"
	case *Interface:
		if isTypeParam() {
			return .sprintf("type parameter %s", )
		}
		return "interface"
	case *Map:
		return "map"
	case *Chan:
		return "chan"
	default:
		return .sprintf("%s", ) // catch-all
	}
}

// If e != nil, it must be the shift expression; it may be nil for non-constant shifts.
func ( *Checker) (,  *operand,  ast.Expr,  token.Token) {
	// TODO(gri) This function seems overly complex. Revisit.

	var  constant.Value
	if .mode == constant_ {
		 = constant.ToInt(.val)
	}

	if allInteger(.typ) || isUntyped(.typ) &&  != nil && .Kind() == constant.Int {
		// The lhs is of integer type or an untyped constant representable
		// as an integer. Nothing to do.
	} else {
		// shift has no chance
		.invalidOp(, _InvalidShiftOperand, "shifted operand %s must be integer", )
		.mode = invalid
		return
	}

	// spec: "The right operand in a shift expression must have integer type
	// or be an untyped constant representable by a value of type uint."

	// Check that constants are representable by uint, but do not convert them
	// (see also issue #47243).
	if .mode == constant_ {
		// Provide a good error message for negative shift counts.
		 := constant.ToInt(.val) // consider -1, 1.0, but not -1.1
		if .Kind() == constant.Int && constant.Sign() < 0 {
			.invalidOp(, _InvalidShiftCount, "negative shift count %s", )
			.mode = invalid
			return
		}

		if isUntyped(.typ) {
			// Caution: Check for representability here, rather than in the switch
			// below, because isInteger includes untyped integers (was bug #43697).
			.representable(, Typ[Uint])
			if .mode == invalid {
				.mode = invalid
				return
			}
		}
	}

	// Check that RHS is otherwise at least of integer type.
	switch {
	case allInteger(.typ):
		if !allUnsigned(.typ) && !.allowVersion(.pkg, 1, 13) {
			.invalidOp(, _InvalidShiftCount, "signed shift count %s requires go1.13 or later", )
			.mode = invalid
			return
		}
	case isUntyped(.typ):
		// This is incorrect, but preserves pre-existing behavior.
		// See also bug #47410.
		.convertUntyped(, Typ[Uint])
		if .mode == invalid {
			.mode = invalid
			return
		}
	default:
		.invalidOp(, _InvalidShiftCount, "shift count %s must be integer", )
		.mode = invalid
		return
	}

	if .mode == constant_ {
		if .mode == constant_ {
			// if either x or y has an unknown value, the result is unknown
			if .val.Kind() == constant.Unknown || .val.Kind() == constant.Unknown {
				.val = constant.MakeUnknown()
				// ensure the correct type - see comment below
				if !isInteger(.typ) {
					.typ = Typ[UntypedInt]
				}
				return
			}
			// rhs must be within reasonable bounds in constant shifts
			const  = 1023 - 1 + 52 // so we can express smallestFloat64 (see issue #44057)
			,  := constant.Uint64Val(.val)
			if ! ||  >  {
				.invalidOp(, _InvalidShiftCount, "invalid shift count %s", )
				.mode = invalid
				return
			}
			// The lhs is representable as an integer but may not be an integer
			// (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(.typ) {
				.typ = Typ[UntypedInt]
			}
			// x is a constant so xval != nil and it must be of Int kind.
			.val = constant.Shift(, , uint())
			.expr = 
			 := .Pos()
			if ,  := .(*ast.BinaryExpr);  != nil {
				 = .OpPos
			}
			.overflow(, , )
			return
		}

		// non-constant shift with constant lhs
		if isUntyped(.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
			// were replaced by its left operand alone.".
			//
			// Delay operand checking until we know the final type
			// by marking the lhs expression as lhs shift operand.
			//
			// Usually (in correct programs), the lhs expression
			// is in the untyped map. However, it is possible to
			// create incorrect programs where the same expression
			// is evaluated twice (via a declaration cycle) such
			// that the lhs expression type is determined in the
			// first round and thus deleted from the map, and then
			// not found in the second round (double insertion of
			// the same expr node still just leads to one entry for
			// that node, and it can only be deleted once).
			// Be cautious and check for presence of entry.
			// Example: var e, f = int(1<<""[f]) // issue 11347
			if ,  := .untyped[.expr];  {
				.isLhs = true
				.untyped[.expr] = 
			}
			// keep x's type
			.mode = value
			return
		}
	}

	// non-constant shift - lhs must be an integer
	if !allInteger(.typ) {
		.invalidOp(, _InvalidShiftOperand, "shifted operand %s must be integer", )
		.mode = invalid
		return
	}

	.mode = value
}

var binaryOpPredicates opPredicates

func init() {
	// Setting binaryOpPredicates in init avoids declaration cycles.
	binaryOpPredicates = opPredicates{
		token.ADD: allNumericOrString,
		token.SUB: allNumeric,
		token.MUL: allNumeric,
		token.QUO: allNumeric,
		token.REM: allInteger,

		token.AND:     allInteger,
		token.OR:      allInteger,
		token.XOR:     allInteger,
		token.AND_NOT: allInteger,

		token.LAND: allBoolean,
		token.LOR:  allBoolean,
	}
}

// If e != nil, it must be the binary expression; it may be nil for non-constant expressions
// (when invoked for an assignment operation where the binary expression is implicit).
func ( *Checker) ( *operand,  ast.Expr, ,  ast.Expr,  token.Token,  token.Pos) {
	var  operand

	.expr(, )
	.expr(&, )

	if .mode == invalid {
		return
	}
	if .mode == invalid {
		.mode = invalid
		.expr = .expr
		return
	}

	if isShift() {
		.shift(, &, , )
		return
	}

	// TODO(gri) make canMix more efficient - called for each binary operation
	 := func(,  *operand) bool {
		if IsInterface(.typ) && !isTypeParam(.typ) || IsInterface(.typ) && !isTypeParam(.typ) {
			return true
		}
		if allBoolean(.typ) != allBoolean(.typ) {
			return false
		}
		if allString(.typ) != allString(.typ) {
			return false
		}
		if .isNil() && !hasNil(.typ) {
			return false
		}
		if .isNil() && !hasNil(.typ) {
			return false
		}
		return true
	}
	if (, &) {
		.convertUntyped(, .typ)
		if .mode == invalid {
			return
		}
		.convertUntyped(&, .typ)
		if .mode == invalid {
			.mode = invalid
			return
		}
	}

	if isComparison() {
		.comparison(, &, , false)
		return
	}

	if !Identical(.typ, .typ) {
		// only report an error if we have valid types
		// (otherwise we had an error reported elsewhere already)
		if .typ != Typ[Invalid] && .typ != Typ[Invalid] {
			var  positioner = 
			if  != nil {
				 = 
			}
			if  != nil {
				.invalidOp(, _MismatchedTypes, "%s (mismatched types %s and %s)", , .typ, .typ)
			} else {
				.invalidOp(, _MismatchedTypes, "%s %s= %s (mismatched types %s and %s)", , , , .typ, .typ)
			}
		}
		.mode = invalid
		return
	}

	if !.op(binaryOpPredicates, , ) {
		.mode = invalid
		return
	}

	if  == token.QUO ||  == token.REM {
		// check for zero divisor
		if (.mode == constant_ || allInteger(.typ)) && .mode == constant_ && constant.Sign(.val) == 0 {
			.invalidOp(&, _DivByZero, "division by zero")
			.mode = invalid
			return
		}

		// check for divisor underflow in complex division (see issue 20227)
		if .mode == constant_ && .mode == constant_ && isComplex(.typ) {
			,  := constant.Real(.val), constant.Imag(.val)
			,  := constant.BinaryOp(, token.MUL, ), constant.BinaryOp(, token.MUL, )
			if constant.Sign() == 0 && constant.Sign() == 0 {
				.invalidOp(&, _DivByZero, "division by zero")
				.mode = invalid
				return
			}
		}
	}

	if .mode == constant_ && .mode == constant_ {
		// if either x or y has an unknown value, the result is unknown
		if .val.Kind() == constant.Unknown || .val.Kind() == constant.Unknown {
			.val = constant.MakeUnknown()
			// x.typ is unchanged
			return
		}
		// force integer division of integer operands
		if  == token.QUO && isInteger(.typ) {
			 = token.QUO_ASSIGN
		}
		.val = constant.BinaryOp(.val, , .val)
		.expr = 
		.overflow(, , )
		return
	}

	.mode = value
	// x.typ is unchanged
}

// exprKind describes the kind of an expression; the kind
// determines if an expression is valid in 'statement context'.
type exprKind int

const (
	conversion exprKind = iota
	expression
	statement
)

// rawExpr typechecks expression e and initializes x with the expression
// value or type. If an error occurred, x.mode is set to invalid.
// If hint != nil, it is the type of a composite literal element.
// If allowGeneric is set, the operand type may be an uninstantiated
// parameterized type or function value.
//
func ( *Checker) ( *operand,  ast.Expr,  Type,  bool) exprKind {
	if trace {
		.trace(.Pos(), "expr %s", )
		.indent++
		defer func() {
			.indent--
			.trace(.Pos(), "=> %s", )
		}()
	}

	 := .exprInternal(, , )

	if ! {
		.nonGeneric()
	}

	.record()

	return 
}

// If x is a generic function or type, nonGeneric reports an error and invalidates x.mode and x.typ.
// Otherwise it leaves x alone.
func ( *Checker) ( *operand) {
	if .mode == invalid || .mode == novalue {
		return
	}
	var  string
	switch t := .typ.(type) {
	case *Named:
		if isGeneric() {
			 = "type"
		}
	case *Signature:
		if .tparams != nil {
			 = "function"
		}
	}
	if  != "" {
		.errorf(.expr, _WrongTypeArgCount, "cannot use generic %s %s without instantiation", , .expr)
		.mode = invalid
		.typ = Typ[Invalid]
	}
}

// exprInternal contains the core of type checking of expressions.
// Must only be called by rawExpr.
//
func ( *Checker) ( *operand,  ast.Expr,  Type) exprKind {
	// make sure x has a valid state in case of bailout
	// (was issue 5770)
	.mode = invalid
	.typ = Typ[Invalid]

	switch e := .(type) {
	case *ast.BadExpr:
		goto  // error was reported before

	case *ast.Ident:
		.ident(, , nil, false)

	case *ast.Ellipsis:
		// ellipses are handled explicitly where they are legal
		// (array composite literals and parameter lists)
		.error(, _BadDotDotDotSyntax, "invalid use of '...'")
		goto 

	case *ast.BasicLit:
		switch .Kind {
		case token.INT, token.FLOAT, token.IMAG:
			.langCompat()
			// The max. mantissa precision for untyped numeric values
			// is 512 bits, or 4048 bits for each of the two integer
			// parts of a fraction for floating-point numbers that are
			// represented accurately in the go/constant package.
			// Constant literals that are longer than this many bits
			// are not meaningful; and excessively long constants may
			// consume a lot of space and time for a useless conversion.
			// Cap constant length with a generous upper limit that also
			// allows for separators between all digits.
			const  = 10000
			if len(.Value) >  {
				.errorf(, _InvalidConstVal, "excessively long constant: %s... (%d chars)", .Value[:10], len(.Value))
				goto 
			}
		}
		.setConst(.Kind, .Value)
		if .mode == invalid {
			// The parser already establishes syntactic correctness.
			// If we reach here it's because of number under-/overflow.
			// TODO(gri) setConst (and in turn the go/constant package)
			// should return an error describing the issue.
			.errorf(, _InvalidConstVal, "malformed constant: %s", .Value)
			goto 
		}

	case *ast.FuncLit:
		if ,  := .typ(.Type).(*Signature);  {
			if !.conf.IgnoreFuncBodies && .Body != nil {
				// Anonymous functions are considered part of the
				// init expression/func declaration which contains
				// them: use existing package-level declaration info.
				 := .decl // capture for use in closure below
				 := .iota // capture for use in closure below (#22345)
				// Don't type-check right away because the function may
				// be part of a type definition to which the function
				// body refers. Instead, type-check as soon as possible,
				// but before the enclosing scope contents changes (#22992).
				.later(func() {
					.funcBody(, "<function literal>", , .Body, )
				})
			}
			.mode = value
			.typ = 
		} else {
			.invalidAST(, "invalid function literal %s", )
			goto 
		}

	case *ast.CompositeLit:
		var ,  Type

		switch {
		case .Type != nil:
			// composite literal type present - use it
			// [...]T array types may only appear with composite literals.
			// Check for them here so we don't have to handle ... in general.
			if ,  := .Type.(*ast.ArrayType);  != nil && .Len != nil {
				if ,  := .Len.(*ast.Ellipsis);  != nil && .Elt == nil {
					// We have an "open" [...]T array type.
					// Create a new ArrayType with unknown length (-1)
					// and finish setting it up after analyzing the literal.
					 = &Array{len: -1, elem: .varType(.Elt)}
					 = 
					break
				}
			}
			 = .typ(.Type)
			 = 

		case  != nil:
			// no composite literal type present - use hint (element type of enclosing type)
			 = 
			, _ = deref(coreType()) // *T implies &T{}
			if  == nil {
				.errorf(, _InvalidLit, "invalid composite literal element type %s: no core type", )
				goto 
			}

		default:
			// TODO(gri) provide better error messages depending on context
			.error(, _UntypedLit, "missing type in composite literal")
			goto 
		}

		switch utyp := coreType().(type) {
		case *Struct:
			// Prevent crash if the struct referred to is not yet set up.
			// See analogous comment for *Array.
			if .fields == nil {
				.error(, _InvalidDeclCycle, "illegal cycle in type declaration")
				goto 
			}
			if len(.Elts) == 0 {
				break
			}
			 := .fields
			if ,  := .Elts[0].(*ast.KeyValueExpr);  {
				// all elements must have keys
				 := make([]bool, len())
				for ,  := range .Elts {
					,  := .(*ast.KeyValueExpr)
					if  == nil {
						.error(, _MixedStructLit, "mixture of field:value and value elements in struct literal")
						continue
					}
					,  := .Key.(*ast.Ident)
					// do all possible checks early (before exiting due to errors)
					// so we don't drop information on the floor
					.expr(, .Value)
					if  == nil {
						.errorf(, _InvalidLitField, "invalid field name %s in struct literal", .Key)
						continue
					}
					 := fieldIndex(.fields, .pkg, .Name)
					if  < 0 {
						.errorf(, _MissingLitField, "unknown field %s in struct literal", .Name)
						continue
					}
					 := []
					.recordUse(, )
					 := .typ
					.assignment(, , "struct literal")
					// 0 <= i < len(fields)
					if [] {
						.errorf(, _DuplicateLitField, "duplicate field name %s in struct literal", .Name)
						continue
					}
					[] = true
				}
			} else {
				// no element must have a key
				for ,  := range .Elts {
					if ,  := .(*ast.KeyValueExpr);  != nil {
						.error(, _MixedStructLit, "mixture of field:value and value elements in struct literal")
						continue
					}
					.expr(, )
					if  >= len() {
						.error(, _InvalidStructLit, "too many values in struct literal")
						break // cannot continue
					}
					// i < len(fields)
					 := []
					if !.Exported() && .pkg != .pkg {
						.errorf(,
							_UnexportedLitField,
							"implicit assignment to unexported field %s in %s literal", .name, )
						continue
					}
					 := .typ
					.assignment(, , "struct literal")
				}
				if len(.Elts) < len() {
					.error(inNode(, .Rbrace), _InvalidStructLit, "too few values in struct literal")
					// ok to continue
				}
			}

		case *Array:
			// Prevent crash if the array referred to is not yet set up. Was issue #18643.
			// This is a stop-gap solution. Should use Checker.objPath to report entire
			// path starting with earliest declaration in the source. TODO(gri) fix this.
			if .elem == nil {
				.error(, _InvalidTypeCycle, "illegal cycle in type declaration")
				goto 
			}
			 := .indexedElts(.Elts, .elem, .len)
			// If we have an array of unknown length (usually [...]T arrays, but also
			// arrays [n]T where n is invalid) set the length now that we know it and
			// record the type for the array (usually done by check.typ which is not
			// called for [...]T). We handle [...]T arrays and arrays with invalid
			// length the same here because it makes sense to "guess" the length for
			// the latter if we have a composite literal; e.g. for [n]int{1, 2, 3}
			// where n is invalid for some reason, it seems fair to assume it should
			// be 3 (see also Checked.arrayLength and issue #27346).
			if .len < 0 {
				.len = 
				// e.Type is missing if we have a composite literal element
				// that is itself a composite literal with omitted type. In
				// that case there is nothing to record (there is no type in
				// the source at that point).
				if .Type != nil {
					.recordTypeAndValue(.Type, typexpr, , nil)
				}
			}

		case *Slice:
			// Prevent crash if the slice referred to is not yet set up.
			// See analogous comment for *Array.
			if .elem == nil {
				.error(, _InvalidTypeCycle, "illegal cycle in type declaration")
				goto 
			}
			.indexedElts(.Elts, .elem, -1)

		case *Map:
			// Prevent crash if the map referred to is not yet set up.
			// See analogous comment for *Array.
			if .key == nil || .elem == nil {
				.error(, _InvalidTypeCycle, "illegal cycle in type declaration")
				goto 
			}
			 := make(map[any][]Type, len(.Elts))
			for ,  := range .Elts {
				,  := .(*ast.KeyValueExpr)
				if  == nil {
					.error(, _MissingLitKey, "missing key in map literal")
					continue
				}
				.exprWithHint(, .Key, .key)
				.assignment(, .key, "map literal")
				if .mode == invalid {
					continue
				}
				if .mode == constant_ {
					 := false
					// if the key is of interface type, the type is also significant when checking for duplicates
					 := keyVal(.val)
					if IsInterface(.key) {
						for ,  := range [] {
							if Identical(, .typ) {
								 = true
								break
							}
						}
						[] = append([], .typ)
					} else {
						_,  = []
						[] = nil
					}
					if  {
						.errorf(, _DuplicateLitKey, "duplicate key %s in map literal", .val)
						continue
					}
				}
				.exprWithHint(, .Value, .elem)
				.assignment(, .elem, "map literal")
			}

		default:
			// when "using" all elements unpack KeyValueExpr
			// explicitly because check.use doesn't accept them
			for ,  := range .Elts {
				if ,  := .(*ast.KeyValueExpr);  != nil {
					// Ideally, we should also "use" kv.Key but we can't know
					// if it's an externally defined struct key or not. Going
					// forward anyway can lead to other errors. Give up instead.
					 = .Value
				}
				.use()
			}
			// if utyp is invalid, an error was reported before
			if  != Typ[Invalid] {
				.errorf(, _InvalidLit, "invalid composite literal type %s", )
				goto 
			}
		}

		.mode = value
		.typ = 

	case *ast.ParenExpr:
		 := .rawExpr(, .X, nil, false)
		.expr = 
		return 

	case *ast.SelectorExpr:
		.selector(, , nil)

	case *ast.IndexExpr, *ast.IndexListExpr:
		 := typeparams.UnpackIndexExpr()
		if .indexExpr(, ) {
			.funcInst(, )
		}
		if .mode == invalid {
			goto 
		}

	case *ast.SliceExpr:
		.sliceExpr(, )
		if .mode == invalid {
			goto 
		}

	case *ast.TypeAssertExpr:
		.expr(, .X)
		if .mode == invalid {
			goto 
		}
		// TODO(gri) we may want to permit type assertions on type parameter values at some point
		if isTypeParam(.typ) {
			.invalidOp(, _InvalidAssert, "cannot use type assertion on type parameter value %s", )
			goto 
		}
		if ,  := under(.typ).(*Interface); ! {
			.invalidOp(, _InvalidAssert, "%s is not an interface", )
			goto 
		}
		// x.(type) expressions are handled explicitly in type switches
		if .Type == nil {
			// Don't use invalidAST because this can occur in the AST produced by
			// go/parser.
			.error(, _BadTypeKeyword, "use of .(type) outside type switch")
			goto 
		}
		 := .varType(.Type)
		if  == Typ[Invalid] {
			goto 
		}
		.typeAssertion(, , , false)
		.mode = commaok
		.typ = 

	case *ast.CallExpr:
		return .callExpr(, )

	case *ast.StarExpr:
		.exprOrType(, .X, false)
		switch .mode {
		case invalid:
			goto 
		case typexpr:
			.validVarType(.X, .typ)
			.typ = &Pointer{base: .typ}
		default:
			var  Type
			if !underIs(.typ, func( Type) bool {
				,  := .(*Pointer)
				if  == nil {
					.invalidOp(, _InvalidIndirection, "cannot indirect %s", )
					return false
				}
				if  != nil && !Identical(.base, ) {
					.invalidOp(, _InvalidIndirection, "pointers of %s must have identical base types", )
					return false
				}
				 = .base
				return true
			}) {
				goto 
			}
			.mode = variable
			.typ = 
		}

	case *ast.UnaryExpr:
		.unary(, )
		if .mode == invalid {
			goto 
		}
		if .Op == token.ARROW {
			.expr = 
			return statement // receive operations may appear in statement context
		}

	case *ast.BinaryExpr:
		.binary(, , .X, .Y, .Op, .OpPos)
		if .mode == invalid {
			goto 
		}

	case *ast.KeyValueExpr:
		// key:value expressions are handled in composite literals
		.invalidAST(, "no key:value expected")
		goto 

	case *ast.ArrayType, *ast.StructType, *ast.FuncType,
		*ast.InterfaceType, *ast.MapType, *ast.ChanType:
		.mode = typexpr
		.typ = .typ()
		// 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
		// performance issue because we only reach here for composite literal
		// types, which are comparatively rare.

	default:
		panic(fmt.Sprintf("%s: unknown expression type %T", .fset.Position(.Pos()), ))
	}

	// everything went well
	.expr = 
	return expression

:
	.mode = invalid
	.expr = 
	return statement // avoid follow-up errors
}

func keyVal( constant.Value) any {
	switch .Kind() {
	case constant.Bool:
		return constant.BoolVal()
	case constant.String:
		return constant.StringVal()
	case constant.Int:
		if ,  := constant.Int64Val();  {
			return 
		}
		if ,  := constant.Uint64Val();  {
			return 
		}
	case constant.Float:
		,  := constant.Float64Val()
		return 
	case constant.Complex:
		,  := constant.Float64Val(constant.Real())
		,  := constant.Float64Val(constant.Imag())
		return complex(, )
	}
	return 
}

// typeAssertion checks x.(T). The type of x must be an interface.
func ( *Checker) ( ast.Expr,  *operand,  Type,  bool) {
	,  := .assertableTo(under(.typ).(*Interface), )
	if  == nil {
		return // success
	}

	 := .missingMethodReason(, .typ, , )

	if  {
		.errorf(, _ImpossibleAssert, "impossible type switch case: %s\n\t%s cannot have dynamic type %s %s", , , , )
		return
	}

	.errorf(, _ImpossibleAssert, "impossible type assertion: %s\n\t%s does not implement %s %s", , , .typ, )
}

// expr typechecks expression e and initializes x with the expression value.
// The result must be a single value.
// If an error occurred, x.mode is set to invalid.
//
func ( *Checker) ( *operand,  ast.Expr) {
	.rawExpr(, , nil, false)
	.exclude(, 1<<novalue|1<<builtin|1<<typexpr)
	.singleValue()
}

// multiExpr is like expr but the result may also be a multi-value.
func ( *Checker) ( *operand,  ast.Expr) {
	.rawExpr(, , nil, false)
	.exclude(, 1<<novalue|1<<builtin|1<<typexpr)
}

// exprWithHint typechecks expression e and initializes x with the expression value;
// hint is the type of a composite literal element.
// If an error occurred, x.mode is set to invalid.
//
func ( *Checker) ( *operand,  ast.Expr,  Type) {
	assert( != nil)
	.rawExpr(, , , false)
	.exclude(, 1<<novalue|1<<builtin|1<<typexpr)
	.singleValue()
}

// exprOrType typechecks expression or type e and initializes x with the expression value or type.
// If allowGeneric is set, the operand type may be an uninstantiated parameterized type or function
// value.
// If an error occurred, x.mode is set to invalid.
//
func ( *Checker) ( *operand,  ast.Expr,  bool) {
	.rawExpr(, , nil, )
	.exclude(, 1<<novalue)
	.singleValue()
}

// exclude reports an error if x.mode is in modeset and sets x.mode to invalid.
// The modeset may contain any of 1<<novalue, 1<<builtin, 1<<typexpr.
func ( *Checker) ( *operand,  uint) {
	if &(1<<.mode) != 0 {
		var  string
		var  errorCode
		switch .mode {
		case novalue:
			if &(1<<typexpr) != 0 {
				 = "%s used as value"
			} else {
				 = "%s used as value or type"
			}
			 = _TooManyValues
		case builtin:
			 = "%s must be called"
			 = _UncalledBuiltin
		case typexpr:
			 = "%s is not an expression"
			 = _NotAnExpr
		default:
			unreachable()
		}
		.errorf(, , , )
		.mode = invalid
	}
}

// singleValue reports an error if x describes a tuple and sets x.mode to invalid.
func ( *Checker) ( *operand) {
	if .mode == value {
		// tuple types are never named - no need for underlying type below
		if ,  := .typ.(*Tuple);  {
			assert(.Len() != 1)
			if compilerErrorMessages {
				.errorf(, _TooManyValues, "multiple-value %s in single-value context", )
			} else {
				.errorf(, _TooManyValues, "%d-valued %s where single value is expected", .Len(), )
			}
			.mode = invalid
		}
	}
}