1
0
mirror of https://github.com/golang/go synced 2024-11-16 19:44:53 -07:00

go/types: ensure that error code values do not change in 1.17

Over this cycle some error code values have changed due to codes being
added/removed. This is probably OK to do once more before we export
error codes in a later Go version, but for now let's keep them stable.

Move things around to correct the changes, and update comments in
errorcodes.go to make it clearer that new codes should be added at the
end.

Change-Id: Id32827ef1a72cfd876ccc039da11d0a1be7470e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/314830
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-04-28 15:49:17 -04:00 committed by Robert Findley
parent 47cb0c46b2
commit c8a92d454c

View File

@ -10,6 +10,8 @@ type errorCode int
// Collectively, these codes provide an identifier that may be used to // Collectively, these codes provide an identifier that may be used to
// implement special handling for certain types of errors. // 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 // 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 // can be easily determined, but coarse enough that they are not an
// implementation detail of the type checking algorithm. As a rule-of-thumb, // implementation detail of the type checking algorithm. As a rule-of-thumb,
@ -34,8 +36,6 @@ const (
// _Test is reserved for errors that only apply while in self-test mode. // _Test is reserved for errors that only apply while in self-test mode.
_Test _Test
/* package names */
// _BlankPkgName occurs when a package name is the blank identifier "_". // _BlankPkgName occurs when a package name is the blank identifier "_".
// //
// Per the spec: // Per the spec:
@ -55,8 +55,6 @@ const (
// var _ = fmt // var _ = fmt
_InvalidPkgUse _InvalidPkgUse
/* imports */
// _BadImportPath occurs when an import path is not valid. // _BadImportPath occurs when an import path is not valid.
_BadImportPath _BadImportPath
@ -81,8 +79,6 @@ const (
// func main() {} // func main() {}
_UnusedImport _UnusedImport
/* initialization */
// _InvalidInitCycle occurs when an invalid cycle is detected within the // _InvalidInitCycle occurs when an invalid cycle is detected within the
// initialization graph. // initialization graph.
// //
@ -92,8 +88,6 @@ const (
// func f() int { return x } // func f() int { return x }
_InvalidInitCycle _InvalidInitCycle
/* decls */
// _DuplicateDecl occurs when an identifier is declared multiple times. // _DuplicateDecl occurs when an identifier is declared multiple times.
// //
// Example: // Example:
@ -122,8 +116,6 @@ const (
// type T [unsafe.Sizeof(T{})]int // type T [unsafe.Sizeof(T{})]int
_InvalidTypeCycle _InvalidTypeCycle
/* decls > const */
// _InvalidConstInit occurs when a const declaration has a non-constant // _InvalidConstInit occurs when a const declaration has a non-constant
// initializer. // initializer.
// //
@ -149,8 +141,6 @@ const (
// const c *int = 4 // const c *int = 4
_InvalidConstType _InvalidConstType
/* decls > var (+ other variable assignment codes) */
// _UntypedNil occurs when the predeclared (untyped) value nil is used to // _UntypedNil occurs when the predeclared (untyped) value nil is used to
// initialize a variable declared without an explicit type. // initialize a variable declared without an explicit type.
// //
@ -249,8 +239,6 @@ const (
// } // }
_UnaddressableFieldAssign _UnaddressableFieldAssign
/* decls > type (+ other type expression codes) */
// _NotAType occurs when the identifier used as the underlying type in a type // _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. // declaration or the right-hand side of a type alias does not denote a type.
// //
@ -320,8 +308,6 @@ const (
// } // }
_InvalidPtrEmbed _InvalidPtrEmbed
/* decls > func and method */
// _BadRecv occurs when a method declaration does not have exactly one // _BadRecv occurs when a method declaration does not have exactly one
// receiver parameter. // receiver parameter.
// //
@ -358,8 +344,6 @@ const (
// func (T) m(i int) int { return i } // func (T) m(i int) int { return i }
_DuplicateMethod _DuplicateMethod
/* decls > special */
// _InvalidBlank occurs when a blank identifier is used as a value or type. // _InvalidBlank occurs when a blank identifier is used as a value or type.
// //
// Per the spec: // Per the spec:
@ -404,8 +388,6 @@ const (
// function, in a main package. // function, in a main package.
_InvalidMainDecl _InvalidMainDecl
/* exprs */
// _TooManyValues occurs when a function returns too many values for the // _TooManyValues occurs when a function returns too many values for the
// expression context in which it is used. // expression context in which it is used.
// //
@ -428,8 +410,6 @@ const (
// } // }
_NotAnExpr _NotAnExpr
/* exprs > const */
// _TruncatedFloat occurs when a float constant is truncated to an integer // _TruncatedFloat occurs when a float constant is truncated to an integer
// value. // value.
// //
@ -443,8 +423,6 @@ const (
// var x int8 = 1000 // var x int8 = 1000
_NumericOverflow _NumericOverflow
/* exprs > operation */
// _UndefinedOp occurs when an operator is not defined for the type(s) used // _UndefinedOp occurs when an operator is not defined for the type(s) used
// in an operation. // in an operation.
// //
@ -479,8 +457,6 @@ const (
// } // }
_NonNumericIncDec _NonNumericIncDec
/* exprs > ptr */
// _UnaddressableOperand occurs when the & operator is applied to an // _UnaddressableOperand occurs when the & operator is applied to an
// unaddressable expression. // unaddressable expression.
// //
@ -496,8 +472,6 @@ const (
// var y = *x // var y = *x
_InvalidIndirection _InvalidIndirection
/* exprs > [] */
// _NonIndexableOperand occurs when an index operation is applied to a value // _NonIndexableOperand occurs when an index operation is applied to a value
// that cannot be indexed. // that cannot be indexed.
// //
@ -530,8 +504,6 @@ const (
// var _ = []int{1,2,3}[2:1] // var _ = []int{1,2,3}[2:1]
_SwappedSliceIndices _SwappedSliceIndices
/* operators > slice */
// _NonSliceableOperand occurs when a slice operation is applied to a value // _NonSliceableOperand occurs when a slice operation is applied to a value
// whose type is not sliceable, or is unaddressable. // whose type is not sliceable, or is unaddressable.
// //
@ -551,8 +523,6 @@ const (
// var x = s[1:2:3] // var x = s[1:2:3]
_InvalidSliceExpr _InvalidSliceExpr
/* exprs > shift */
// _InvalidShiftCount occurs when the right-hand side of a shift operation is // _InvalidShiftCount occurs when the right-hand side of a shift operation is
// either non-integer, negative, or too large. // either non-integer, negative, or too large.
// //
@ -570,8 +540,6 @@ const (
// var x = s << 2 // var x = s << 2
_InvalidShiftOperand _InvalidShiftOperand
/* exprs > chan */
// _InvalidReceive occurs when there is a channel receive from a value that // _InvalidReceive occurs when there is a channel receive from a value that
// is either not a channel, or is a send-only channel. // is either not a channel, or is a send-only channel.
// //
@ -592,8 +560,6 @@ const (
// } // }
_InvalidSend _InvalidSend
/* exprs > literal */
// _DuplicateLitKey occurs when an index is duplicated in a slice, array, or // _DuplicateLitKey occurs when an index is duplicated in a slice, array, or
// map literal. // map literal.
// //
@ -683,8 +649,6 @@ const (
// var _ = P {} // var _ = P {}
_InvalidLit _InvalidLit
/* exprs > selector */
// _AmbiguousSelector occurs when a selector is ambiguous. // _AmbiguousSelector occurs when a selector is ambiguous.
// //
// Example: // Example:
@ -730,8 +694,6 @@ const (
// var x = T{}.f // var x = T{}.f
_MissingFieldOrMethod _MissingFieldOrMethod
/* exprs > ... */
// _BadDotDotDotSyntax occurs when a "..." occurs in a context where it is // _BadDotDotDotSyntax occurs when a "..." occurs in a context where it is
// not valid. // not valid.
// //
@ -762,6 +724,8 @@ const (
// func f(...int, int) // func f(...int, int)
_MisplacedDotDotDot _MisplacedDotDotDot
_ // _InvalidDotDotDotOperand was removed.
// _InvalidDotDotDot occurs when a "..." is used in a non-variadic built-in // _InvalidDotDotDot occurs when a "..." is used in a non-variadic built-in
// function. // function.
// //
@ -770,8 +734,6 @@ const (
// var l = len(s...) // var l = len(s...)
_InvalidDotDotDot _InvalidDotDotDot
/* exprs > built-in */
// _UncalledBuiltin occurs when a built-in function is used as a // _UncalledBuiltin occurs when a built-in function is used as a
// function-valued expression, instead of being called. // function-valued expression, instead of being called.
// //
@ -883,47 +845,6 @@ const (
// var _ = real(int(1)) // var _ = real(int(1))
_InvalidReal _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 // _InvalidAssert occurs when a type assertion is applied to a
// value that is not of interface type. // value that is not of interface type.
// //
@ -947,8 +868,6 @@ const (
// var _ = x.(T) // var _ = x.(T)
_ImpossibleAssert _ImpossibleAssert
/* exprs > conversion */
// _InvalidConversion occurs when the argument type cannot be converted to the // _InvalidConversion occurs when the argument type cannot be converted to the
// target. // target.
// //
@ -968,8 +887,6 @@ const (
// var _ = 1 + "" // var _ = 1 + ""
_InvalidUntypedConversion _InvalidUntypedConversion
/* offsetof */
// _BadOffsetofSyntax occurs when unsafe.Offsetof is called with an argument // _BadOffsetofSyntax occurs when unsafe.Offsetof is called with an argument
// that is not a selector expression. // that is not a selector expression.
// //
@ -1008,8 +925,6 @@ const (
// var _ = unsafe.Offsetof(s.m) // var _ = unsafe.Offsetof(s.m)
_InvalidOffsetof _InvalidOffsetof
/* control flow > scope */
// _UnusedExpr occurs when a side-effect free expression is used as a // _UnusedExpr occurs when a side-effect free expression is used as a
// statement. Such a statement has no effect. // statement. Such a statement has no effect.
// //
@ -1057,8 +972,6 @@ const (
// } // }
_OutOfScopeResult _OutOfScopeResult
/* control flow > if */
// _InvalidCond occurs when an if condition is not a boolean expression. // _InvalidCond occurs when an if condition is not a boolean expression.
// //
// Example: // Example:
@ -1069,8 +982,6 @@ const (
// } // }
_InvalidCond _InvalidCond
/* control flow > for */
// _InvalidPostDecl occurs when there is a declaration in a for-loop post // _InvalidPostDecl occurs when there is a declaration in a for-loop post
// statement. // statement.
// //
@ -1080,6 +991,8 @@ const (
// } // }
_InvalidPostDecl _InvalidPostDecl
_ // _InvalidChanRange was removed.
// _InvalidIterVar occurs when two iteration variables are used while ranging // _InvalidIterVar occurs when two iteration variables are used while ranging
// over a channel. // over a channel.
// //
@ -1102,8 +1015,6 @@ const (
// } // }
_InvalidRangeExpr _InvalidRangeExpr
/* control flow > switch */
// _MisplacedBreak occurs when a break statement is not within a for, switch, // _MisplacedBreak occurs when a break statement is not within a for, switch,
// or select statement of the innermost function definition. // or select statement of the innermost function definition.
// //
@ -1207,8 +1118,6 @@ const (
// } // }
_InvalidExprSwitch _InvalidExprSwitch
/* control flow > select */
// _InvalidSelectCase occurs when a select case is not a channel send or // _InvalidSelectCase occurs when a select case is not a channel send or
// receive. // receive.
// //
@ -1223,8 +1132,6 @@ const (
// } // }
_InvalidSelectCase _InvalidSelectCase
/* control flow > labels and jumps */
// _UndeclaredLabel occurs when an undeclared label is jumped to. // _UndeclaredLabel occurs when an undeclared label is jumped to.
// //
// Example: // Example:
@ -1292,8 +1199,6 @@ const (
// } // }
_JumpIntoBlock _JumpIntoBlock
/* control flow > calls */
// _InvalidMethodExpr occurs when a pointer method is called but the argument // _InvalidMethodExpr occurs when a pointer method is called but the argument
// is not addressable. // is not addressable.
// //
@ -1321,8 +1226,6 @@ const (
// var y = x() // var y = x()
_InvalidCall _InvalidCall
/* control flow > suspended */
// _UnusedResults occurs when a restricted expression-only built-in function // _UnusedResults occurs when a restricted expression-only built-in function
// is suspended via go or defer. Such a suspension discards the results of // is suspended via go or defer. Such a suspension discards the results of
// these side-effect free built-in functions, and therefore is ineffectual. // these side-effect free built-in functions, and therefore is ineffectual.
@ -1354,6 +1257,8 @@ const (
// } // }
_InvalidGo _InvalidGo
// All codes below were added in Go 1.17.
// _BadDecl occurs when a declaration has invalid syntax. // _BadDecl occurs when a declaration has invalid syntax.
_BadDecl _BadDecl
@ -1366,6 +1271,45 @@ const (
// } // }
_RepeatedDecl _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 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(rFindley) remove this error code after deciding on errors for generics code.
_Todo _Todo