github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/types/errors/codes.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package errors
     6  
     7  type Code int
     8  
     9  // This file defines the error codes that can be produced during type-checking.
    10  // Collectively, these codes provide an identifier that may be used to
    11  // implement special handling for certain types of errors.
    12  //
    13  // Error code values should not be changed: add new codes at the end.
    14  //
    15  // Error codes should be fine-grained enough that the exact nature of the error
    16  // can be easily determined, but coarse enough that they are not an
    17  // implementation detail of the type checking algorithm. As a rule-of-thumb,
    18  // errors should be considered equivalent if there is a theoretical refactoring
    19  // of the type checker in which they are emitted in exactly one place. For
    20  // example, the type checker emits different error messages for "too many
    21  // arguments" and "too few arguments", but one can imagine an alternative type
    22  // checker where this check instead just emits a single "wrong number of
    23  // arguments", so these errors should have the same code.
    24  //
    25  // Error code names should be as brief as possible while retaining accuracy and
    26  // distinctiveness. In most cases names should start with an adjective
    27  // describing the nature of the error (e.g. "invalid", "unused", "misplaced"),
    28  // and end with a noun identifying the relevant language object. For example,
    29  // "_DuplicateDecl" or "_InvalidSliceExpr". For brevity, naming follows the
    30  // convention that "bad" implies a problem with syntax, and "invalid" implies a
    31  // problem with types.
    32  
    33  const (
    34  	// InvalidSyntaxTree occurs if an invalid syntax tree is provided
    35  	// to the type checker. It should never happen.
    36  	InvalidSyntaxTree Code = -1
    37  )
    38  
    39  const (
    40  	// The zero Code value indicates an unset (invalid) error code.
    41  	_ Code = iota
    42  
    43  	// Test is reserved for errors that only apply while in self-test mode.
    44  	Test
    45  
    46  	// BlankPkgName occurs when a package name is the blank identifier "_".
    47  	//
    48  	// Per the spec:
    49  	//  "The PackageName must not be the blank identifier."
    50  	//
    51  	// Example:
    52  	//  package _
    53  	BlankPkgName
    54  
    55  	// MismatchedPkgName occurs when a file's package name doesn't match the
    56  	// package name already established by other files.
    57  	MismatchedPkgName
    58  
    59  	// InvalidPkgUse occurs when a package identifier is used outside of a
    60  	// selector expression.
    61  	//
    62  	// Example:
    63  	//  import "fmt"
    64  	//
    65  	//  var _ = fmt
    66  	InvalidPkgUse
    67  
    68  	// BadImportPath occurs when an import path is not valid.
    69  	BadImportPath
    70  
    71  	// BrokenImport occurs when importing a package fails.
    72  	//
    73  	// Example:
    74  	//  import "amissingpackage"
    75  	BrokenImport
    76  
    77  	// ImportCRenamed occurs when the special import "C" is renamed. "C" is a
    78  	// pseudo-package, and must not be renamed.
    79  	//
    80  	// Example:
    81  	//  import _ "C"
    82  	ImportCRenamed
    83  
    84  	// UnusedImport occurs when an import is unused.
    85  	//
    86  	// Example:
    87  	//  import "fmt"
    88  	//
    89  	//  func main() {}
    90  	UnusedImport
    91  
    92  	// InvalidInitCycle occurs when an invalid cycle is detected within the
    93  	// initialization graph.
    94  	//
    95  	// Example:
    96  	//  var x int = f()
    97  	//
    98  	//  func f() int { return x }
    99  	InvalidInitCycle
   100  
   101  	// DuplicateDecl occurs when an identifier is declared multiple times.
   102  	//
   103  	// Example:
   104  	//  var x = 1
   105  	//  var x = 2
   106  	DuplicateDecl
   107  
   108  	// InvalidDeclCycle occurs when a declaration cycle is not valid.
   109  	//
   110  	// Example:
   111  	//  type S struct {
   112  	//  	S
   113  	//  }
   114  	//
   115  	InvalidDeclCycle
   116  
   117  	// InvalidTypeCycle occurs when a cycle in type definitions results in a
   118  	// type that is not well-defined.
   119  	//
   120  	// Example:
   121  	//  import "unsafe"
   122  	//
   123  	//  type T [unsafe.Sizeof(T{})]int
   124  	InvalidTypeCycle
   125  
   126  	// InvalidConstInit occurs when a const declaration has a non-constant
   127  	// initializer.
   128  	//
   129  	// Example:
   130  	//  var x int
   131  	//  const _ = x
   132  	InvalidConstInit
   133  
   134  	// InvalidConstVal occurs when a const value cannot be converted to its
   135  	// target type.
   136  	//
   137  	// TODO(findleyr): this error code and example are not very clear. Consider
   138  	// removing it.
   139  	//
   140  	// Example:
   141  	//  const _ = 1 << "hello"
   142  	InvalidConstVal
   143  
   144  	// InvalidConstType occurs when the underlying type in a const declaration
   145  	// is not a valid constant type.
   146  	//
   147  	// Example:
   148  	//  const c *int = 4
   149  	InvalidConstType
   150  
   151  	// UntypedNilUse occurs when the predeclared (untyped) value nil is used to
   152  	// initialize a variable declared without an explicit type.
   153  	//
   154  	// Example:
   155  	//  var x = nil
   156  	UntypedNilUse
   157  
   158  	// WrongAssignCount occurs when the number of values on the right-hand side
   159  	// of an assignment or initialization expression does not match the number
   160  	// of variables on the left-hand side.
   161  	//
   162  	// Example:
   163  	//  var x = 1, 2
   164  	WrongAssignCount
   165  
   166  	// UnassignableOperand occurs when the left-hand side of an assignment is
   167  	// not assignable.
   168  	//
   169  	// Example:
   170  	//  func f() {
   171  	//  	const c = 1
   172  	//  	c = 2
   173  	//  }
   174  	UnassignableOperand
   175  
   176  	// NoNewVar occurs when a short variable declaration (':=') does not declare
   177  	// new variables.
   178  	//
   179  	// Example:
   180  	//  func f() {
   181  	//  	x := 1
   182  	//  	x := 2
   183  	//  }
   184  	NoNewVar
   185  
   186  	// MultiValAssignOp occurs when an assignment operation (+=, *=, etc) does
   187  	// not have single-valued left-hand or right-hand side.
   188  	//
   189  	// Per the spec:
   190  	//  "In assignment operations, both the left- and right-hand expression lists
   191  	//  must contain exactly one single-valued expression"
   192  	//
   193  	// Example:
   194  	//  func f() int {
   195  	//  	x, y := 1, 2
   196  	//  	x, y += 1
   197  	//  	return x + y
   198  	//  }
   199  	MultiValAssignOp
   200  
   201  	// InvalidIfaceAssign occurs when a value of type T is used as an
   202  	// interface, but T does not implement a method of the expected interface.
   203  	//
   204  	// Example:
   205  	//  type I interface {
   206  	//  	f()
   207  	//  }
   208  	//
   209  	//  type T int
   210  	//
   211  	//  var x I = T(1)
   212  	InvalidIfaceAssign
   213  
   214  	// InvalidChanAssign occurs when a chan assignment is invalid.
   215  	//
   216  	// Per the spec, a value x is assignable to a channel type T if:
   217  	//  "x is a bidirectional channel value, T is a channel type, x's type V and
   218  	//  T have identical element types, and at least one of V or T is not a
   219  	//  defined type."
   220  	//
   221  	// Example:
   222  	//  type T1 chan int
   223  	//  type T2 chan int
   224  	//
   225  	//  var x T1
   226  	//  // Invalid assignment because both types are named
   227  	//  var _ T2 = x
   228  	InvalidChanAssign
   229  
   230  	// IncompatibleAssign occurs when the type of the right-hand side expression
   231  	// in an assignment cannot be assigned to the type of the variable being
   232  	// assigned.
   233  	//
   234  	// Example:
   235  	//  var x []int
   236  	//  var _ int = x
   237  	IncompatibleAssign
   238  
   239  	// UnaddressableFieldAssign occurs when trying to assign to a struct field
   240  	// in a map value.
   241  	//
   242  	// Example:
   243  	//  func f() {
   244  	//  	m := make(map[string]struct{i int})
   245  	//  	m["foo"].i = 42
   246  	//  }
   247  	UnaddressableFieldAssign
   248  
   249  	// NotAType occurs when the identifier used as the underlying type in a type
   250  	// declaration or the right-hand side of a type alias does not denote a type.
   251  	//
   252  	// Example:
   253  	//  var S = 2
   254  	//
   255  	//  type T S
   256  	NotAType
   257  
   258  	// InvalidArrayLen occurs when an array length is not a constant value.
   259  	//
   260  	// Example:
   261  	//  var n = 3
   262  	//  var _ = [n]int{}
   263  	InvalidArrayLen
   264  
   265  	// BlankIfaceMethod occurs when a method name is '_'.
   266  	//
   267  	// Per the spec:
   268  	//  "The name of each explicitly specified method must be unique and not
   269  	//  blank."
   270  	//
   271  	// Example:
   272  	//  type T interface {
   273  	//  	_(int)
   274  	//  }
   275  	BlankIfaceMethod
   276  
   277  	// IncomparableMapKey occurs when a map key type does not support the == and
   278  	// != operators.
   279  	//
   280  	// Per the spec:
   281  	//  "The comparison operators == and != must be fully defined for operands of
   282  	//  the key type; thus the key type must not be a function, map, or slice."
   283  	//
   284  	// Example:
   285  	//  var x map[T]int
   286  	//
   287  	//  type T []int
   288  	IncomparableMapKey
   289  
   290  	// InvalidIfaceEmbed occurs when a non-interface type is embedded in an
   291  	// interface (for go 1.17 or earlier).
   292  	_ // not used anymore
   293  
   294  	// InvalidPtrEmbed occurs when an embedded field is of the pointer form *T,
   295  	// and T itself is itself a pointer, an unsafe.Pointer, or an interface.
   296  	//
   297  	// Per the spec:
   298  	//  "An embedded field must be specified as a type name T or as a pointer to
   299  	//  a non-interface type name *T, and T itself may not be a pointer type."
   300  	//
   301  	// Example:
   302  	//  type T *int
   303  	//
   304  	//  type S struct {
   305  	//  	*T
   306  	//  }
   307  	InvalidPtrEmbed
   308  
   309  	// BadRecv occurs when a method declaration does not have exactly one
   310  	// receiver parameter.
   311  	//
   312  	// Example:
   313  	//  func () _() {}
   314  	BadRecv
   315  
   316  	// InvalidRecv occurs when a receiver type expression is not of the form T
   317  	// or *T, or T is a pointer type.
   318  	//
   319  	// Example:
   320  	//  type T struct {}
   321  	//
   322  	//  func (**T) m() {}
   323  	InvalidRecv
   324  
   325  	// DuplicateFieldAndMethod occurs when an identifier appears as both a field
   326  	// and method name.
   327  	//
   328  	// Example:
   329  	//  type T struct {
   330  	//  	m int
   331  	//  }
   332  	//
   333  	//  func (T) m() {}
   334  	DuplicateFieldAndMethod
   335  
   336  	// DuplicateMethod occurs when two methods on the same receiver type have
   337  	// the same name.
   338  	//
   339  	// Example:
   340  	//  type T struct {}
   341  	//  func (T) m() {}
   342  	//  func (T) m(i int) int { return i }
   343  	DuplicateMethod
   344  
   345  	// InvalidBlank occurs when a blank identifier is used as a value or type.
   346  	//
   347  	// Per the spec:
   348  	//  "The blank identifier may appear as an operand only on the left-hand side
   349  	//  of an assignment."
   350  	//
   351  	// Example:
   352  	//  var x = _
   353  	InvalidBlank
   354  
   355  	// InvalidIota occurs when the predeclared identifier iota is used outside
   356  	// of a constant declaration.
   357  	//
   358  	// Example:
   359  	//  var x = iota
   360  	InvalidIota
   361  
   362  	// MissingInitBody occurs when an init function is missing its body.
   363  	//
   364  	// Example:
   365  	//  func init()
   366  	MissingInitBody
   367  
   368  	// InvalidInitSig occurs when an init function declares parameters or
   369  	// results.
   370  	//
   371  	// Deprecated: no longer emitted by the type checker. _InvalidInitDecl is
   372  	// used instead.
   373  	InvalidInitSig
   374  
   375  	// InvalidInitDecl occurs when init is declared as anything other than a
   376  	// function.
   377  	//
   378  	// Example:
   379  	//  var init = 1
   380  	//
   381  	// Example:
   382  	//  func init() int { return 1 }
   383  	InvalidInitDecl
   384  
   385  	// InvalidMainDecl occurs when main is declared as anything other than a
   386  	// function, in a main package.
   387  	InvalidMainDecl
   388  
   389  	// TooManyValues occurs when a function returns too many values for the
   390  	// expression context in which it is used.
   391  	//
   392  	// Example:
   393  	//  func ReturnTwo() (int, int) {
   394  	//  	return 1, 2
   395  	//  }
   396  	//
   397  	//  var x = ReturnTwo()
   398  	TooManyValues
   399  
   400  	// NotAnExpr occurs when a type expression is used where a value expression
   401  	// is expected.
   402  	//
   403  	// Example:
   404  	//  type T struct {}
   405  	//
   406  	//  func f() {
   407  	//  	T
   408  	//  }
   409  	NotAnExpr
   410  
   411  	// TruncatedFloat occurs when a float constant is truncated to an integer
   412  	// value.
   413  	//
   414  	// Example:
   415  	//  var _ int = 98.6
   416  	TruncatedFloat
   417  
   418  	// NumericOverflow occurs when a numeric constant overflows its target type.
   419  	//
   420  	// Example:
   421  	//  var x int8 = 1000
   422  	NumericOverflow
   423  
   424  	// UndefinedOp occurs when an operator is not defined for the type(s) used
   425  	// in an operation.
   426  	//
   427  	// Example:
   428  	//  var c = "a" - "b"
   429  	UndefinedOp
   430  
   431  	// MismatchedTypes occurs when operand types are incompatible in a binary
   432  	// operation.
   433  	//
   434  	// Example:
   435  	//  var a = "hello"
   436  	//  var b = 1
   437  	//  var c = a - b
   438  	MismatchedTypes
   439  
   440  	// DivByZero occurs when a division operation is provable at compile
   441  	// time to be a division by zero.
   442  	//
   443  	// Example:
   444  	//  const divisor = 0
   445  	//  var x int = 1/divisor
   446  	DivByZero
   447  
   448  	// NonNumericIncDec occurs when an increment or decrement operator is
   449  	// applied to a non-numeric value.
   450  	//
   451  	// Example:
   452  	//  func f() {
   453  	//  	var c = "c"
   454  	//  	c++
   455  	//  }
   456  	NonNumericIncDec
   457  
   458  	// UnaddressableOperand occurs when the & operator is applied to an
   459  	// unaddressable expression.
   460  	//
   461  	// Example:
   462  	//  var x = &1
   463  	UnaddressableOperand
   464  
   465  	// InvalidIndirection occurs when a non-pointer value is indirected via the
   466  	// '*' operator.
   467  	//
   468  	// Example:
   469  	//  var x int
   470  	//  var y = *x
   471  	InvalidIndirection
   472  
   473  	// NonIndexableOperand occurs when an index operation is applied to a value
   474  	// that cannot be indexed.
   475  	//
   476  	// Example:
   477  	//  var x = 1
   478  	//  var y = x[1]
   479  	NonIndexableOperand
   480  
   481  	// InvalidIndex occurs when an index argument is not of integer type,
   482  	// negative, or out-of-bounds.
   483  	//
   484  	// Example:
   485  	//  var s = [...]int{1,2,3}
   486  	//  var x = s[5]
   487  	//
   488  	// Example:
   489  	//  var s = []int{1,2,3}
   490  	//  var _ = s[-1]
   491  	//
   492  	// Example:
   493  	//  var s = []int{1,2,3}
   494  	//  var i string
   495  	//  var _ = s[i]
   496  	InvalidIndex
   497  
   498  	// SwappedSliceIndices occurs when constant indices in a slice expression
   499  	// are decreasing in value.
   500  	//
   501  	// Example:
   502  	//  var _ = []int{1,2,3}[2:1]
   503  	SwappedSliceIndices
   504  
   505  	// NonSliceableOperand occurs when a slice operation is applied to a value
   506  	// whose type is not sliceable, or is unaddressable.
   507  	//
   508  	// Example:
   509  	//  var x = [...]int{1, 2, 3}[:1]
   510  	//
   511  	// Example:
   512  	//  var x = 1
   513  	//  var y = 1[:1]
   514  	NonSliceableOperand
   515  
   516  	// InvalidSliceExpr occurs when a three-index slice expression (a[x:y:z]) is
   517  	// applied to a string.
   518  	//
   519  	// Example:
   520  	//  var s = "hello"
   521  	//  var x = s[1:2:3]
   522  	InvalidSliceExpr
   523  
   524  	// InvalidShiftCount occurs when the right-hand side of a shift operation is
   525  	// either non-integer, negative, or too large.
   526  	//
   527  	// Example:
   528  	//  var (
   529  	//  	x string
   530  	//  	y int = 1 << x
   531  	//  )
   532  	InvalidShiftCount
   533  
   534  	// InvalidShiftOperand occurs when the shifted operand is not an integer.
   535  	//
   536  	// Example:
   537  	//  var s = "hello"
   538  	//  var x = s << 2
   539  	InvalidShiftOperand
   540  
   541  	// InvalidReceive occurs when there is a channel receive from a value that
   542  	// is either not a channel, or is a send-only channel.
   543  	//
   544  	// Example:
   545  	//  func f() {
   546  	//  	var x = 1
   547  	//  	<-x
   548  	//  }
   549  	InvalidReceive
   550  
   551  	// InvalidSend occurs when there is a channel send to a value that is not a
   552  	// channel, or is a receive-only channel.
   553  	//
   554  	// Example:
   555  	//  func f() {
   556  	//  	var x = 1
   557  	//  	x <- "hello!"
   558  	//  }
   559  	InvalidSend
   560  
   561  	// DuplicateLitKey occurs when an index is duplicated in a slice, array, or
   562  	// map literal.
   563  	//
   564  	// Example:
   565  	//  var _ = []int{0:1, 0:2}
   566  	//
   567  	// Example:
   568  	//  var _ = map[string]int{"a": 1, "a": 2}
   569  	DuplicateLitKey
   570  
   571  	// MissingLitKey occurs when a map literal is missing a key expression.
   572  	//
   573  	// Example:
   574  	//  var _ = map[string]int{1}
   575  	MissingLitKey
   576  
   577  	// InvalidLitIndex occurs when the key in a key-value element of a slice or
   578  	// array literal is not an integer constant.
   579  	//
   580  	// Example:
   581  	//  var i = 0
   582  	//  var x = []string{i: "world"}
   583  	InvalidLitIndex
   584  
   585  	// OversizeArrayLit occurs when an array literal exceeds its length.
   586  	//
   587  	// Example:
   588  	//  var _ = [2]int{1,2,3}
   589  	OversizeArrayLit
   590  
   591  	// MixedStructLit occurs when a struct literal contains a mix of positional
   592  	// and named elements.
   593  	//
   594  	// Example:
   595  	//  var _ = struct{i, j int}{i: 1, 2}
   596  	MixedStructLit
   597  
   598  	// InvalidStructLit occurs when a positional struct literal has an incorrect
   599  	// number of values.
   600  	//
   601  	// Example:
   602  	//  var _ = struct{i, j int}{1,2,3}
   603  	InvalidStructLit
   604  
   605  	// MissingLitField occurs when a struct literal refers to a field that does
   606  	// not exist on the struct type.
   607  	//
   608  	// Example:
   609  	//  var _ = struct{i int}{j: 2}
   610  	MissingLitField
   611  
   612  	// DuplicateLitField occurs when a struct literal contains duplicated
   613  	// fields.
   614  	//
   615  	// Example:
   616  	//  var _ = struct{i int}{i: 1, i: 2}
   617  	DuplicateLitField
   618  
   619  	// UnexportedLitField occurs when a positional struct literal implicitly
   620  	// assigns an unexported field of an imported type.
   621  	UnexportedLitField
   622  
   623  	// InvalidLitField occurs when a field name is not a valid identifier.
   624  	//
   625  	// Example:
   626  	//  var _ = struct{i int}{1: 1}
   627  	InvalidLitField
   628  
   629  	// UntypedLit occurs when a composite literal omits a required type
   630  	// identifier.
   631  	//
   632  	// Example:
   633  	//  type outer struct{
   634  	//  	inner struct { i int }
   635  	//  }
   636  	//
   637  	//  var _ = outer{inner: {1}}
   638  	UntypedLit
   639  
   640  	// InvalidLit occurs when a composite literal expression does not match its
   641  	// type.
   642  	//
   643  	// Example:
   644  	//  type P *struct{
   645  	//  	x int
   646  	//  }
   647  	//  var _ = P {}
   648  	InvalidLit
   649  
   650  	// AmbiguousSelector occurs when a selector is ambiguous.
   651  	//
   652  	// Example:
   653  	//  type E1 struct { i int }
   654  	//  type E2 struct { i int }
   655  	//  type T struct { E1; E2 }
   656  	//
   657  	//  var x T
   658  	//  var _ = x.i
   659  	AmbiguousSelector
   660  
   661  	// UndeclaredImportedName occurs when a package-qualified identifier is
   662  	// undeclared by the imported package.
   663  	//
   664  	// Example:
   665  	//  import "go/types"
   666  	//
   667  	//  var _ = types.NotAnActualIdentifier
   668  	UndeclaredImportedName
   669  
   670  	// UnexportedName occurs when a selector refers to an unexported identifier
   671  	// of an imported package.
   672  	//
   673  	// Example:
   674  	//  import "reflect"
   675  	//
   676  	//  type _ reflect.flag
   677  	UnexportedName
   678  
   679  	// UndeclaredName occurs when an identifier is not declared in the current
   680  	// scope.
   681  	//
   682  	// Example:
   683  	//  var x T
   684  	UndeclaredName
   685  
   686  	// MissingFieldOrMethod occurs when a selector references a field or method
   687  	// that does not exist.
   688  	//
   689  	// Example:
   690  	//  type T struct {}
   691  	//
   692  	//  var x = T{}.f
   693  	MissingFieldOrMethod
   694  
   695  	// BadDotDotDotSyntax occurs when a "..." occurs in a context where it is
   696  	// not valid.
   697  	//
   698  	// Example:
   699  	//  var _ = map[int][...]int{0: {}}
   700  	BadDotDotDotSyntax
   701  
   702  	// NonVariadicDotDotDot occurs when a "..." is used on the final argument to
   703  	// a non-variadic function.
   704  	//
   705  	// Example:
   706  	//  func printArgs(s []string) {
   707  	//  	for _, a := range s {
   708  	//  		println(a)
   709  	//  	}
   710  	//  }
   711  	//
   712  	//  func f() {
   713  	//  	s := []string{"a", "b", "c"}
   714  	//  	printArgs(s...)
   715  	//  }
   716  	NonVariadicDotDotDot
   717  
   718  	// MisplacedDotDotDot occurs when a "..." is used somewhere other than the
   719  	// final argument in a function declaration.
   720  	//
   721  	// Example:
   722  	// 	func f(...int, int)
   723  	MisplacedDotDotDot
   724  
   725  	_ // InvalidDotDotDotOperand was removed.
   726  
   727  	// InvalidDotDotDot occurs when a "..." is used in a non-variadic built-in
   728  	// function.
   729  	//
   730  	// Example:
   731  	//  var s = []int{1, 2, 3}
   732  	//  var l = len(s...)
   733  	InvalidDotDotDot
   734  
   735  	// UncalledBuiltin occurs when a built-in function is used as a
   736  	// function-valued expression, instead of being called.
   737  	//
   738  	// Per the spec:
   739  	//  "The built-in functions do not have standard Go types, so they can only
   740  	//  appear in call expressions; they cannot be used as function values."
   741  	//
   742  	// Example:
   743  	//  var _ = copy
   744  	UncalledBuiltin
   745  
   746  	// InvalidAppend occurs when append is called with a first argument that is
   747  	// not a slice.
   748  	//
   749  	// Example:
   750  	//  var _ = append(1, 2)
   751  	InvalidAppend
   752  
   753  	// InvalidCap occurs when an argument to the cap built-in function is not of
   754  	// supported type.
   755  	//
   756  	// See https://golang.org/ref/spec#Length_and_capacity for information on
   757  	// which underlying types are supported as arguments to cap and len.
   758  	//
   759  	// Example:
   760  	//  var s = 2
   761  	//  var x = cap(s)
   762  	InvalidCap
   763  
   764  	// InvalidClose occurs when close(...) is called with an argument that is
   765  	// not of channel type, or that is a receive-only channel.
   766  	//
   767  	// Example:
   768  	//  func f() {
   769  	//  	var x int
   770  	//  	close(x)
   771  	//  }
   772  	InvalidClose
   773  
   774  	// InvalidCopy occurs when the arguments are not of slice type or do not
   775  	// have compatible type.
   776  	//
   777  	// See https://golang.org/ref/spec#Appending_and_copying_slices for more
   778  	// information on the type requirements for the copy built-in.
   779  	//
   780  	// Example:
   781  	//  func f() {
   782  	//  	var x []int
   783  	//  	y := []int64{1,2,3}
   784  	//  	copy(x, y)
   785  	//  }
   786  	InvalidCopy
   787  
   788  	// InvalidComplex occurs when the complex built-in function is called with
   789  	// arguments with incompatible types.
   790  	//
   791  	// Example:
   792  	//  var _ = complex(float32(1), float64(2))
   793  	InvalidComplex
   794  
   795  	// InvalidDelete occurs when the delete built-in function is called with a
   796  	// first argument that is not a map.
   797  	//
   798  	// Example:
   799  	//  func f() {
   800  	//  	m := "hello"
   801  	//  	delete(m, "e")
   802  	//  }
   803  	InvalidDelete
   804  
   805  	// InvalidImag occurs when the imag built-in function is called with an
   806  	// argument that does not have complex type.
   807  	//
   808  	// Example:
   809  	//  var _ = imag(int(1))
   810  	InvalidImag
   811  
   812  	// InvalidLen occurs when an argument to the len built-in function is not of
   813  	// supported type.
   814  	//
   815  	// See https://golang.org/ref/spec#Length_and_capacity for information on
   816  	// which underlying types are supported as arguments to cap and len.
   817  	//
   818  	// Example:
   819  	//  var s = 2
   820  	//  var x = len(s)
   821  	InvalidLen
   822  
   823  	// SwappedMakeArgs occurs when make is called with three arguments, and its
   824  	// length argument is larger than its capacity argument.
   825  	//
   826  	// Example:
   827  	//  var x = make([]int, 3, 2)
   828  	SwappedMakeArgs
   829  
   830  	// InvalidMake occurs when make is called with an unsupported type argument.
   831  	//
   832  	// See https://golang.org/ref/spec#Making_slices_maps_and_channels for
   833  	// information on the types that may be created using make.
   834  	//
   835  	// Example:
   836  	//  var x = make(int)
   837  	InvalidMake
   838  
   839  	// InvalidReal occurs when the real built-in function is called with an
   840  	// argument that does not have complex type.
   841  	//
   842  	// Example:
   843  	//  var _ = real(int(1))
   844  	InvalidReal
   845  
   846  	// InvalidAssert occurs when a type assertion is applied to a
   847  	// value that is not of interface type.
   848  	//
   849  	// Example:
   850  	//  var x = 1
   851  	//  var _ = x.(float64)
   852  	InvalidAssert
   853  
   854  	// ImpossibleAssert occurs for a type assertion x.(T) when the value x of
   855  	// interface cannot have dynamic type T, due to a missing or mismatching
   856  	// method on T.
   857  	//
   858  	// Example:
   859  	//  type T int
   860  	//
   861  	//  func (t *T) m() int { return int(*t) }
   862  	//
   863  	//  type I interface { m() int }
   864  	//
   865  	//  var x I
   866  	//  var _ = x.(T)
   867  	ImpossibleAssert
   868  
   869  	// InvalidConversion occurs when the argument type cannot be converted to the
   870  	// target.
   871  	//
   872  	// See https://golang.org/ref/spec#Conversions for the rules of
   873  	// convertibility.
   874  	//
   875  	// Example:
   876  	//  var x float64
   877  	//  var _ = string(x)
   878  	InvalidConversion
   879  
   880  	// InvalidUntypedConversion occurs when there is no valid implicit
   881  	// conversion from an untyped value satisfying the type constraints of the
   882  	// context in which it is used.
   883  	//
   884  	// Example:
   885  	//  var _ = 1 + []int{}
   886  	InvalidUntypedConversion
   887  
   888  	// BadOffsetofSyntax occurs when unsafe.Offsetof is called with an argument
   889  	// that is not a selector expression.
   890  	//
   891  	// Example:
   892  	//  import "unsafe"
   893  	//
   894  	//  var x int
   895  	//  var _ = unsafe.Offsetof(x)
   896  	BadOffsetofSyntax
   897  
   898  	// InvalidOffsetof occurs when unsafe.Offsetof is called with a method
   899  	// selector, rather than a field selector, or when the field is embedded via
   900  	// a pointer.
   901  	//
   902  	// Per the spec:
   903  	//
   904  	//  "If f is an embedded field, it must be reachable without pointer
   905  	//  indirections through fields of the struct. "
   906  	//
   907  	// Example:
   908  	//  import "unsafe"
   909  	//
   910  	//  type T struct { f int }
   911  	//  type S struct { *T }
   912  	//  var s S
   913  	//  var _ = unsafe.Offsetof(s.f)
   914  	//
   915  	// Example:
   916  	//  import "unsafe"
   917  	//
   918  	//  type S struct{}
   919  	//
   920  	//  func (S) m() {}
   921  	//
   922  	//  var s S
   923  	//  var _ = unsafe.Offsetof(s.m)
   924  	InvalidOffsetof
   925  
   926  	// UnusedExpr occurs when a side-effect free expression is used as a
   927  	// statement. Such a statement has no effect.
   928  	//
   929  	// Example:
   930  	//  func f(i int) {
   931  	//  	i*i
   932  	//  }
   933  	UnusedExpr
   934  
   935  	// UnusedVar occurs when a variable is declared but unused.
   936  	//
   937  	// Example:
   938  	//  func f() {
   939  	//  	x := 1
   940  	//  }
   941  	UnusedVar
   942  
   943  	// MissingReturn occurs when a function with results is missing a return
   944  	// statement.
   945  	//
   946  	// Example:
   947  	//  func f() int {}
   948  	MissingReturn
   949  
   950  	// WrongResultCount occurs when a return statement returns an incorrect
   951  	// number of values.
   952  	//
   953  	// Example:
   954  	//  func ReturnOne() int {
   955  	//  	return 1, 2
   956  	//  }
   957  	WrongResultCount
   958  
   959  	// OutOfScopeResult occurs when the name of a value implicitly returned by
   960  	// an empty return statement is shadowed in a nested scope.
   961  	//
   962  	// Example:
   963  	//  func factor(n int) (i int) {
   964  	//  	for i := 2; i < n; i++ {
   965  	//  		if n%i == 0 {
   966  	//  			return
   967  	//  		}
   968  	//  	}
   969  	//  	return 0
   970  	//  }
   971  	OutOfScopeResult
   972  
   973  	// InvalidCond occurs when an if condition is not a boolean expression.
   974  	//
   975  	// Example:
   976  	//  func checkReturn(i int) {
   977  	//  	if i {
   978  	//  		panic("non-zero return")
   979  	//  	}
   980  	//  }
   981  	InvalidCond
   982  
   983  	// InvalidPostDecl occurs when there is a declaration in a for-loop post
   984  	// statement.
   985  	//
   986  	// Example:
   987  	//  func f() {
   988  	//  	for i := 0; i < 10; j := 0 {}
   989  	//  }
   990  	InvalidPostDecl
   991  
   992  	_ // InvalidChanRange was removed.
   993  
   994  	// InvalidIterVar occurs when two iteration variables are used while ranging
   995  	// over a channel.
   996  	//
   997  	// Example:
   998  	//  func f(c chan int) {
   999  	//  	for k, v := range c {
  1000  	//  		println(k, v)
  1001  	//  	}
  1002  	//  }
  1003  	InvalidIterVar
  1004  
  1005  	// InvalidRangeExpr occurs when the type of a range expression is not array,
  1006  	// slice, string, map, or channel.
  1007  	//
  1008  	// Example:
  1009  	//  func f(i int) {
  1010  	//  	for j := range i {
  1011  	//  		println(j)
  1012  	//  	}
  1013  	//  }
  1014  	InvalidRangeExpr
  1015  
  1016  	// MisplacedBreak occurs when a break statement is not within a for, switch,
  1017  	// or select statement of the innermost function definition.
  1018  	//
  1019  	// Example:
  1020  	//  func f() {
  1021  	//  	break
  1022  	//  }
  1023  	MisplacedBreak
  1024  
  1025  	// MisplacedContinue occurs when a continue statement is not within a for
  1026  	// loop of the innermost function definition.
  1027  	//
  1028  	// Example:
  1029  	//  func sumeven(n int) int {
  1030  	//  	proceed := func() {
  1031  	//  		continue
  1032  	//  	}
  1033  	//  	sum := 0
  1034  	//  	for i := 1; i <= n; i++ {
  1035  	//  		if i % 2 != 0 {
  1036  	//  			proceed()
  1037  	//  		}
  1038  	//  		sum += i
  1039  	//  	}
  1040  	//  	return sum
  1041  	//  }
  1042  	MisplacedContinue
  1043  
  1044  	// MisplacedFallthrough occurs when a fallthrough statement is not within an
  1045  	// expression switch.
  1046  	//
  1047  	// Example:
  1048  	//  func typename(i interface{}) string {
  1049  	//  	switch i.(type) {
  1050  	//  	case int64:
  1051  	//  		fallthrough
  1052  	//  	case int:
  1053  	//  		return "int"
  1054  	//  	}
  1055  	//  	return "unsupported"
  1056  	//  }
  1057  	MisplacedFallthrough
  1058  
  1059  	// DuplicateCase occurs when a type or expression switch has duplicate
  1060  	// cases.
  1061  	//
  1062  	// Example:
  1063  	//  func printInt(i int) {
  1064  	//  	switch i {
  1065  	//  	case 1:
  1066  	//  		println("one")
  1067  	//  	case 1:
  1068  	//  		println("One")
  1069  	//  	}
  1070  	//  }
  1071  	DuplicateCase
  1072  
  1073  	// DuplicateDefault occurs when a type or expression switch has multiple
  1074  	// default clauses.
  1075  	//
  1076  	// Example:
  1077  	//  func printInt(i int) {
  1078  	//  	switch i {
  1079  	//  	case 1:
  1080  	//  		println("one")
  1081  	//  	default:
  1082  	//  		println("One")
  1083  	//  	default:
  1084  	//  		println("1")
  1085  	//  	}
  1086  	//  }
  1087  	DuplicateDefault
  1088  
  1089  	// BadTypeKeyword occurs when a .(type) expression is used anywhere other
  1090  	// than a type switch.
  1091  	//
  1092  	// Example:
  1093  	//  type I interface {
  1094  	//  	m()
  1095  	//  }
  1096  	//  var t I
  1097  	//  var _ = t.(type)
  1098  	BadTypeKeyword
  1099  
  1100  	// InvalidTypeSwitch occurs when .(type) is used on an expression that is
  1101  	// not of interface type.
  1102  	//
  1103  	// Example:
  1104  	//  func f(i int) {
  1105  	//  	switch x := i.(type) {}
  1106  	//  }
  1107  	InvalidTypeSwitch
  1108  
  1109  	// InvalidExprSwitch occurs when a switch expression is not comparable.
  1110  	//
  1111  	// Example:
  1112  	//  func _() {
  1113  	//  	var a struct{ _ func() }
  1114  	//  	switch a /* ERROR cannot switch on a */ {
  1115  	//  	}
  1116  	//  }
  1117  	InvalidExprSwitch
  1118  
  1119  	// InvalidSelectCase occurs when a select case is not a channel send or
  1120  	// receive.
  1121  	//
  1122  	// Example:
  1123  	//  func checkChan(c <-chan int) bool {
  1124  	//  	select {
  1125  	//  	case c:
  1126  	//  		return true
  1127  	//  	default:
  1128  	//  		return false
  1129  	//  	}
  1130  	//  }
  1131  	InvalidSelectCase
  1132  
  1133  	// UndeclaredLabel occurs when an undeclared label is jumped to.
  1134  	//
  1135  	// Example:
  1136  	//  func f() {
  1137  	//  	goto L
  1138  	//  }
  1139  	UndeclaredLabel
  1140  
  1141  	// DuplicateLabel occurs when a label is declared more than once.
  1142  	//
  1143  	// Example:
  1144  	//  func f() int {
  1145  	//  L:
  1146  	//  L:
  1147  	//  	return 1
  1148  	//  }
  1149  	DuplicateLabel
  1150  
  1151  	// MisplacedLabel occurs when a break or continue label is not on a for,
  1152  	// switch, or select statement.
  1153  	//
  1154  	// Example:
  1155  	//  func f() {
  1156  	//  L:
  1157  	//  	a := []int{1,2,3}
  1158  	//  	for _, e := range a {
  1159  	//  		if e > 10 {
  1160  	//  			break L
  1161  	//  		}
  1162  	//  		println(a)
  1163  	//  	}
  1164  	//  }
  1165  	MisplacedLabel
  1166  
  1167  	// UnusedLabel occurs when a label is declared and not used.
  1168  	//
  1169  	// Example:
  1170  	//  func f() {
  1171  	//  L:
  1172  	//  }
  1173  	UnusedLabel
  1174  
  1175  	// JumpOverDecl occurs when a label jumps over a variable declaration.
  1176  	//
  1177  	// Example:
  1178  	//  func f() int {
  1179  	//  	goto L
  1180  	//  	x := 2
  1181  	//  L:
  1182  	//  	x++
  1183  	//  	return x
  1184  	//  }
  1185  	JumpOverDecl
  1186  
  1187  	// JumpIntoBlock occurs when a forward jump goes to a label inside a nested
  1188  	// block.
  1189  	//
  1190  	// Example:
  1191  	//  func f(x int) {
  1192  	//  	goto L
  1193  	//  	if x > 0 {
  1194  	//  	L:
  1195  	//  		print("inside block")
  1196  	//  	}
  1197  	// }
  1198  	JumpIntoBlock
  1199  
  1200  	// InvalidMethodExpr occurs when a pointer method is called but the argument
  1201  	// is not addressable.
  1202  	//
  1203  	// Example:
  1204  	//  type T struct {}
  1205  	//
  1206  	//  func (*T) m() int { return 1 }
  1207  	//
  1208  	//  var _ = T.m(T{})
  1209  	InvalidMethodExpr
  1210  
  1211  	// WrongArgCount occurs when too few or too many arguments are passed by a
  1212  	// function call.
  1213  	//
  1214  	// Example:
  1215  	//  func f(i int) {}
  1216  	//  var x = f()
  1217  	WrongArgCount
  1218  
  1219  	// InvalidCall occurs when an expression is called that is not of function
  1220  	// type.
  1221  	//
  1222  	// Example:
  1223  	//  var x = "x"
  1224  	//  var y = x()
  1225  	InvalidCall
  1226  
  1227  	// UnusedResults occurs when a restricted expression-only built-in function
  1228  	// is suspended via go or defer. Such a suspension discards the results of
  1229  	// these side-effect free built-in functions, and therefore is ineffectual.
  1230  	//
  1231  	// Example:
  1232  	//  func f(a []int) int {
  1233  	//  	defer len(a)
  1234  	//  	return i
  1235  	//  }
  1236  	UnusedResults
  1237  
  1238  	// InvalidDefer occurs when a deferred expression is not a function call,
  1239  	// for example if the expression is a type conversion.
  1240  	//
  1241  	// Example:
  1242  	//  func f(i int) int {
  1243  	//  	defer int32(i)
  1244  	//  	return i
  1245  	//  }
  1246  	InvalidDefer
  1247  
  1248  	// InvalidGo occurs when a go expression is not a function call, for example
  1249  	// if the expression is a type conversion.
  1250  	//
  1251  	// Example:
  1252  	//  func f(i int) int {
  1253  	//  	go int32(i)
  1254  	//  	return i
  1255  	//  }
  1256  	InvalidGo
  1257  
  1258  	// All codes below were added in Go 1.17.
  1259  
  1260  	// BadDecl occurs when a declaration has invalid syntax.
  1261  	BadDecl
  1262  
  1263  	// RepeatedDecl occurs when an identifier occurs more than once on the left
  1264  	// hand side of a short variable declaration.
  1265  	//
  1266  	// Example:
  1267  	//  func _() {
  1268  	//  	x, y, y := 1, 2, 3
  1269  	//  }
  1270  	RepeatedDecl
  1271  
  1272  	// InvalidUnsafeAdd occurs when unsafe.Add is called with a
  1273  	// length argument that is not of integer type.
  1274  	// It also occurs if it is used in a package compiled for a
  1275  	// language version before go1.17.
  1276  	//
  1277  	// Example:
  1278  	//  import "unsafe"
  1279  	//
  1280  	//  var p unsafe.Pointer
  1281  	//  var _ = unsafe.Add(p, float64(1))
  1282  	InvalidUnsafeAdd
  1283  
  1284  	// InvalidUnsafeSlice occurs when unsafe.Slice is called with a
  1285  	// pointer argument that is not of pointer type or a length argument
  1286  	// that is not of integer type, negative, or out of bounds.
  1287  	// It also occurs if it is used in a package compiled for a language
  1288  	// version before go1.17.
  1289  	//
  1290  	// Example:
  1291  	//  import "unsafe"
  1292  	//
  1293  	//  var x int
  1294  	//  var _ = unsafe.Slice(x, 1)
  1295  	//
  1296  	// Example:
  1297  	//  import "unsafe"
  1298  	//
  1299  	//  var x int
  1300  	//  var _ = unsafe.Slice(&x, float64(1))
  1301  	//
  1302  	// Example:
  1303  	//  import "unsafe"
  1304  	//
  1305  	//  var x int
  1306  	//  var _ = unsafe.Slice(&x, -1)
  1307  	//
  1308  	// Example:
  1309  	//  import "unsafe"
  1310  	//
  1311  	//  var x int
  1312  	//  var _ = unsafe.Slice(&x, uint64(1) << 63)
  1313  	InvalidUnsafeSlice
  1314  
  1315  	// All codes below were added in Go 1.18.
  1316  
  1317  	// UnsupportedFeature occurs when a language feature is used that is not
  1318  	// supported at this Go version.
  1319  	UnsupportedFeature
  1320  
  1321  	// NotAGenericType occurs when a non-generic type is used where a generic
  1322  	// type is expected: in type or function instantiation.
  1323  	//
  1324  	// Example:
  1325  	//  type T int
  1326  	//
  1327  	//  var _ T[int]
  1328  	NotAGenericType
  1329  
  1330  	// WrongTypeArgCount occurs when a type or function is instantiated with an
  1331  	// incorrent number of type arguments, including when a generic type or
  1332  	// function is used without instantiation.
  1333  	//
  1334  	// Errors inolving failed type inference are assigned other error codes.
  1335  	//
  1336  	// Example:
  1337  	//  type T[p any] int
  1338  	//
  1339  	//  var _ T[int, string]
  1340  	//
  1341  	// Example:
  1342  	//  func f[T any]() {}
  1343  	//
  1344  	//  var x = f
  1345  	WrongTypeArgCount
  1346  
  1347  	// CannotInferTypeArgs occurs when type or function type argument inference
  1348  	// fails to infer all type arguments.
  1349  	//
  1350  	// Example:
  1351  	//  func f[T any]() {}
  1352  	//
  1353  	//  func _() {
  1354  	//  	f()
  1355  	//  }
  1356  	CannotInferTypeArgs
  1357  
  1358  	// InvalidTypeArg occurs when a type argument does not satisfy its
  1359  	// corresponding type parameter constraints.
  1360  	//
  1361  	// Example:
  1362  	//  type T[P ~int] struct{}
  1363  	//
  1364  	//  var _ T[string]
  1365  	InvalidTypeArg // arguments? InferenceFailed
  1366  
  1367  	// InvalidInstanceCycle occurs when an invalid cycle is detected
  1368  	// within the instantiation graph.
  1369  	//
  1370  	// Example:
  1371  	//  func f[T any]() { f[*T]() }
  1372  	InvalidInstanceCycle
  1373  
  1374  	// InvalidUnion occurs when an embedded union or approximation element is
  1375  	// not valid.
  1376  	//
  1377  	// Example:
  1378  	//  type _ interface {
  1379  	//   	~int | interface{ m() }
  1380  	//  }
  1381  	InvalidUnion
  1382  
  1383  	// MisplacedConstraintIface occurs when a constraint-type interface is used
  1384  	// outside of constraint position.
  1385  	//
  1386  	// Example:
  1387  	//   type I interface { ~int }
  1388  	//
  1389  	//   var _ I
  1390  	MisplacedConstraintIface
  1391  
  1392  	// InvalidMethodTypeParams occurs when methods have type parameters.
  1393  	//
  1394  	// It cannot be encountered with an AST parsed using go/parser.
  1395  	InvalidMethodTypeParams
  1396  
  1397  	// MisplacedTypeParam occurs when a type parameter is used in a place where
  1398  	// it is not permitted.
  1399  	//
  1400  	// Example:
  1401  	//  type T[P any] P
  1402  	//
  1403  	// Example:
  1404  	//  type T[P any] struct{ *P }
  1405  	MisplacedTypeParam
  1406  
  1407  	// InvalidUnsafeSliceData occurs when unsafe.SliceData is called with
  1408  	// an argument that is not of slice type. It also occurs if it is used
  1409  	// in a package compiled for a language version before go1.20.
  1410  	//
  1411  	// Example:
  1412  	//  import "unsafe"
  1413  	//
  1414  	//  var x int
  1415  	//  var _ = unsafe.SliceData(x)
  1416  	InvalidUnsafeSliceData
  1417  
  1418  	// InvalidUnsafeString occurs when unsafe.String is called with
  1419  	// a length argument that is not of integer type, negative, or
  1420  	// out of bounds. It also occurs if it is used in a package
  1421  	// compiled for a language version before go1.20.
  1422  	//
  1423  	// Example:
  1424  	//  import "unsafe"
  1425  	//
  1426  	//  var b [10]byte
  1427  	//  var _ = unsafe.String(&b[0], -1)
  1428  	InvalidUnsafeString
  1429  
  1430  	// InvalidUnsafeStringData occurs if it is used in a package
  1431  	// compiled for a language version before go1.20.
  1432  	_ // not used anymore
  1433  
  1434  	// InvalidClear occurs when clear is called with an argument
  1435  	// that is not of map, slice, or pointer-to-array type.
  1436  	//
  1437  	// Example:
  1438  	//  func _(x int) {
  1439  	//  	clear(x)
  1440  	//  }
  1441  	InvalidClear
  1442  )