// Collectively, these codes provide an identifier that may be used to
// implement special handling for certain types of errors.
//
+// Error code values should not be changed: add new codes at the end.
+//
// Error codes should be fine-grained enough that the exact nature of the error
// can be easily determined, but coarse enough that they are not an
// implementation detail of the type checking algorithm. As a rule-of-thumb,
// _Test is reserved for errors that only apply while in self-test mode.
_Test
- /* package names */
-
// _BlankPkgName occurs when a package name is the blank identifier "_".
//
// Per the spec:
// var _ = fmt
_InvalidPkgUse
- /* imports */
-
// _BadImportPath occurs when an import path is not valid.
_BadImportPath
// func main() {}
_UnusedImport
- /* initialization */
-
// _InvalidInitCycle occurs when an invalid cycle is detected within the
// initialization graph.
//
// func f() int { return x }
_InvalidInitCycle
- /* decls */
-
// _DuplicateDecl occurs when an identifier is declared multiple times.
//
// Example:
// type T [unsafe.Sizeof(T{})]int
_InvalidTypeCycle
- /* decls > const */
-
// _InvalidConstInit occurs when a const declaration has a non-constant
// initializer.
//
// const c *int = 4
_InvalidConstType
- /* decls > var (+ other variable assignment codes) */
-
// _UntypedNil occurs when the predeclared (untyped) value nil is used to
// initialize a variable declared without an explicit type.
//
// }
_UnaddressableFieldAssign
- /* decls > type (+ other type expression codes) */
-
// _NotAType occurs when the identifier used as the underlying type in a type
// declaration or the right-hand side of a type alias does not denote a type.
//
// }
_InvalidPtrEmbed
- /* decls > func and method */
-
// _BadRecv occurs when a method declaration does not have exactly one
// receiver parameter.
//
// func (T) m(i int) int { return i }
_DuplicateMethod
- /* decls > special */
-
// _InvalidBlank occurs when a blank identifier is used as a value or type.
//
// Per the spec:
// function, in a main package.
_InvalidMainDecl
- /* exprs */
-
// _TooManyValues occurs when a function returns too many values for the
// expression context in which it is used.
//
// }
_NotAnExpr
- /* exprs > const */
-
// _TruncatedFloat occurs when a float constant is truncated to an integer
// value.
//
// var x int8 = 1000
_NumericOverflow
- /* exprs > operation */
-
// _UndefinedOp occurs when an operator is not defined for the type(s) used
// in an operation.
//
// }
_NonNumericIncDec
- /* exprs > ptr */
-
// _UnaddressableOperand occurs when the & operator is applied to an
// unaddressable expression.
//
// var y = *x
_InvalidIndirection
- /* exprs > [] */
-
// _NonIndexableOperand occurs when an index operation is applied to a value
// that cannot be indexed.
//
// var _ = []int{1,2,3}[2:1]
_SwappedSliceIndices
- /* operators > slice */
-
// _NonSliceableOperand occurs when a slice operation is applied to a value
// whose type is not sliceable, or is unaddressable.
//
// var x = s[1:2:3]
_InvalidSliceExpr
- /* exprs > shift */
-
// _InvalidShiftCount occurs when the right-hand side of a shift operation is
// either non-integer, negative, or too large.
//
// var x = s << 2
_InvalidShiftOperand
- /* exprs > chan */
-
// _InvalidReceive occurs when there is a channel receive from a value that
// is either not a channel, or is a send-only channel.
//
// }
_InvalidSend
- /* exprs > literal */
-
// _DuplicateLitKey occurs when an index is duplicated in a slice, array, or
// map literal.
//
// var _ = P {}
_InvalidLit
- /* exprs > selector */
-
// _AmbiguousSelector occurs when a selector is ambiguous.
//
// Example:
// var x = T{}.f
_MissingFieldOrMethod
- /* exprs > ... */
-
// _BadDotDotDotSyntax occurs when a "..." occurs in a context where it is
// not valid.
//
// func f(...int, int)
_MisplacedDotDotDot
+ _ // _InvalidDotDotDotOperand was removed.
+
// _InvalidDotDotDot occurs when a "..." is used in a non-variadic built-in
// function.
//
// var l = len(s...)
_InvalidDotDotDot
- /* exprs > built-in */
-
// _UncalledBuiltin occurs when a built-in function is used as a
// function-valued expression, instead of being called.
//
// var _ = real(int(1))
_InvalidReal
- // _InvalidUnsafeAdd occurs when unsafe.Add is called with a
- // length argument that is not of integer type.
- //
- // Example:
- // import "unsafe"
- //
- // var p unsafe.Pointer
- // var _ = unsafe.Add(p, float64(1))
- _InvalidUnsafeAdd
-
- // _InvalidUnsafeSlice occurs when unsafe.Slice is called with a
- // pointer argument that is not of pointer type or a length argument
- // that is not of integer type, negative, or out of bounds.
- //
- // Example:
- // import "unsafe"
- //
- // var x int
- // var _ = unsafe.Slice(x, 1)
- //
- // Example:
- // import "unsafe"
- //
- // var x int
- // var _ = unsafe.Slice(&x, float64(1))
- //
- // Example:
- // import "unsafe"
- //
- // var x int
- // var _ = unsafe.Slice(&x, -1)
- //
- // Example:
- // import "unsafe"
- //
- // var x int
- // var _ = unsafe.Slice(&x, uint64(1) << 63)
- _InvalidUnsafeSlice
-
- /* exprs > assertion */
-
// _InvalidAssert occurs when a type assertion is applied to a
// value that is not of interface type.
//
// var _ = x.(T)
_ImpossibleAssert
- /* exprs > conversion */
-
// _InvalidConversion occurs when the argument type cannot be converted to the
// target.
//
// var _ = 1 + ""
_InvalidUntypedConversion
- /* offsetof */
-
// _BadOffsetofSyntax occurs when unsafe.Offsetof is called with an argument
// that is not a selector expression.
//
// var _ = unsafe.Offsetof(s.m)
_InvalidOffsetof
- /* control flow > scope */
-
// _UnusedExpr occurs when a side-effect free expression is used as a
// statement. Such a statement has no effect.
//
// }
_OutOfScopeResult
- /* control flow > if */
-
// _InvalidCond occurs when an if condition is not a boolean expression.
//
// Example:
// }
_InvalidCond
- /* control flow > for */
-
// _InvalidPostDecl occurs when there is a declaration in a for-loop post
// statement.
//
// }
_InvalidPostDecl
+ _ // _InvalidChanRange was removed.
+
// _InvalidIterVar occurs when two iteration variables are used while ranging
// over a channel.
//
// }
_InvalidRangeExpr
- /* control flow > switch */
-
// _MisplacedBreak occurs when a break statement is not within a for, switch,
// or select statement of the innermost function definition.
//
// }
_InvalidExprSwitch
- /* control flow > select */
-
// _InvalidSelectCase occurs when a select case is not a channel send or
// receive.
//
// }
_InvalidSelectCase
- /* control flow > labels and jumps */
-
// _UndeclaredLabel occurs when an undeclared label is jumped to.
//
// Example:
// }
_JumpIntoBlock
- /* control flow > calls */
-
// _InvalidMethodExpr occurs when a pointer method is called but the argument
// is not addressable.
//
// var y = x()
_InvalidCall
- /* control flow > suspended */
-
// _UnusedResults occurs when a restricted expression-only built-in function
// is suspended via go or defer. Such a suspension discards the results of
// these side-effect free built-in functions, and therefore is ineffectual.
// }
_InvalidGo
+ // All codes below were added in Go 1.17.
+
// _BadDecl occurs when a declaration has invalid syntax.
_BadDecl
// }
_RepeatedDecl
+ // _InvalidUnsafeAdd occurs when unsafe.Add is called with a
+ // length argument that is not of integer type.
+ //
+ // Example:
+ // import "unsafe"
+ //
+ // var p unsafe.Pointer
+ // var _ = unsafe.Add(p, float64(1))
+ _InvalidUnsafeAdd
+
+ // _InvalidUnsafeSlice occurs when unsafe.Slice is called with a
+ // pointer argument that is not of pointer type or a length argument
+ // that is not of integer type, negative, or out of bounds.
+ //
+ // Example:
+ // import "unsafe"
+ //
+ // var x int
+ // var _ = unsafe.Slice(x, 1)
+ //
+ // Example:
+ // import "unsafe"
+ //
+ // var x int
+ // var _ = unsafe.Slice(&x, float64(1))
+ //
+ // Example:
+ // import "unsafe"
+ //
+ // var x int
+ // var _ = unsafe.Slice(&x, -1)
+ //
+ // Example:
+ // import "unsafe"
+ //
+ // var x int
+ // var _ = unsafe.Slice(&x, uint64(1) << 63)
+ _InvalidUnsafeSlice
+
// _Todo is a placeholder for error codes that have not been decided.
// TODO(rFindley) remove this error code after deciding on errors for generics code.
_Todo