]> Cypherpunks.ru repositories - gostls13.git/blob - src/go/types/errorcodes.go
[dev.typeparams] merge master (2f0da6d) into dev.typeparams
[gostls13.git] / src / go / types / errorcodes.go
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 types
6
7 type errorCode int
8
9 // TODO(rFindley): ensure that existing error codes do not change in the
10 //                 dev.typeparams branch.
11
12 // This file defines the error codes that can be produced during type-checking.
13 // Collectively, these codes provide an identifier that may be used to
14 // implement special handling for certain types of errors.
15 //
16 // Error codes should be fine-grained enough that the exact nature of the error
17 // can be easily determined, but coarse enough that they are not an
18 // implementation detail of the type checking algorithm. As a rule-of-thumb,
19 // errors should be considered equivalent if there is a theoretical refactoring
20 // of the type checker in which they are emitted in exactly one place. For
21 // example, the type checker emits different error messages for "too many
22 // arguments" and "too few arguments", but one can imagine an alternative type
23 // checker where this check instead just emits a single "wrong number of
24 // arguments", so these errors should have the same code.
25 //
26 // Error code names should be as brief as possible while retaining accuracy and
27 // distinctiveness. In most cases names should start with an adjective
28 // describing the nature of the error (e.g. "invalid", "unused", "misplaced"),
29 // and end with a noun identifying the relevant language object. For example,
30 // "_DuplicateDecl" or "_InvalidSliceExpr". For brevity, naming follows the
31 // convention that "bad" implies a problem with syntax, and "invalid" implies a
32 // problem with types.
33
34 const (
35         _ errorCode = iota
36
37         // _Test is reserved for errors that only apply while in self-test mode.
38         _Test
39
40         /* package names */
41
42         // _BlankPkgName occurs when a package name is the blank identifier "_".
43         //
44         // Per the spec:
45         //  "The PackageName must not be the blank identifier."
46         _BlankPkgName
47
48         // _MismatchedPkgName occurs when a file's package name doesn't match the
49         // package name already established by other files.
50         _MismatchedPkgName
51
52         // _InvalidPkgUse occurs when a package identifier is used outside of a
53         // selector expression.
54         //
55         // Example:
56         //  import "fmt"
57         //
58         //  var _ = fmt
59         _InvalidPkgUse
60
61         /* imports */
62
63         // _BadImportPath occurs when an import path is not valid.
64         _BadImportPath
65
66         // _BrokenImport occurs when importing a package fails.
67         //
68         // Example:
69         //  import "amissingpackage"
70         _BrokenImport
71
72         // _ImportCRenamed occurs when the special import "C" is renamed. "C" is a
73         // pseudo-package, and must not be renamed.
74         //
75         // Example:
76         //  import _ "C"
77         _ImportCRenamed
78
79         // _UnusedImport occurs when an import is unused.
80         //
81         // Example:
82         //  import "fmt"
83         //
84         //  func main() {}
85         _UnusedImport
86
87         /* initialization */
88
89         // _InvalidInitCycle occurs when an invalid cycle is detected within the
90         // initialization graph.
91         //
92         // Example:
93         //  var x int = f()
94         //
95         //  func f() int { return x }
96         _InvalidInitCycle
97
98         /* decls */
99
100         // _DuplicateDecl occurs when an identifier is declared multiple times.
101         //
102         // Example:
103         //  var x = 1
104         //  var x = 2
105         _DuplicateDecl
106
107         // _InvalidDeclCycle occurs when a declaration cycle is not valid.
108         //
109         // Example:
110         //  import "unsafe"
111         //
112         //  type T struct {
113         //      a [n]int
114         //  }
115         //
116         //  var n = unsafe.Sizeof(T{})
117         _InvalidDeclCycle
118
119         // _InvalidTypeCycle occurs when a cycle in type definitions results in a
120         // type that is not well-defined.
121         //
122         // Example:
123         //  import "unsafe"
124         //
125         //  type T [unsafe.Sizeof(T{})]int
126         _InvalidTypeCycle
127
128         /* decls > const */
129
130         // _InvalidConstInit occurs when a const declaration has a non-constant
131         // initializer.
132         //
133         // Example:
134         //  var x int
135         //  const _ = x
136         _InvalidConstInit
137
138         // _InvalidConstVal occurs when a const value cannot be converted to its
139         // target type.
140         //
141         // TODO(findleyr): this error code and example are not very clear. Consider
142         // removing it.
143         //
144         // Example:
145         //  const _ = 1 << "hello"
146         _InvalidConstVal
147
148         // _InvalidConstType occurs when the underlying type in a const declaration
149         // is not a valid constant type.
150         //
151         // Example:
152         //  const c *int = 4
153         _InvalidConstType
154
155         /* decls > var (+ other variable assignment codes) */
156
157         // _UntypedNil occurs when the predeclared (untyped) value nil is used to
158         // initialize a variable declared without an explicit type.
159         //
160         // Example:
161         //  var x = nil
162         _UntypedNil
163
164         // _WrongAssignCount occurs when the number of values on the right-hand side
165         // of an assignment or or initialization expression does not match the number
166         // of variables on the left-hand side.
167         //
168         // Example:
169         //  var x = 1, 2
170         _WrongAssignCount
171
172         // _UnassignableOperand occurs when the left-hand side of an assignment is
173         // not assignable.
174         //
175         // Example:
176         //  func f() {
177         //      const c = 1
178         //      c = 2
179         //  }
180         _UnassignableOperand
181
182         // _NoNewVar occurs when a short variable declaration (':=') does not declare
183         // new variables.
184         //
185         // Example:
186         //  func f() {
187         //      x := 1
188         //      x := 2
189         //  }
190         _NoNewVar
191
192         // _MultiValAssignOp occurs when an assignment operation (+=, *=, etc) does
193         // not have single-valued left-hand or right-hand side.
194         //
195         // Per the spec:
196         //  "In assignment operations, both the left- and right-hand expression lists
197         //  must contain exactly one single-valued expression"
198         //
199         // Example:
200         //  func f() int {
201         //      x, y := 1, 2
202         //      x, y += 1
203         //      return x + y
204         //  }
205         _MultiValAssignOp
206
207         // _InvalidIfaceAssign occurs when a value of type T is used as an
208         // interface, but T does not implement a method of the expected interface.
209         //
210         // Example:
211         //  type I interface {
212         //      f()
213         //  }
214         //
215         //  type T int
216         //
217         //  var x I = T(1)
218         _InvalidIfaceAssign
219
220         // _InvalidChanAssign occurs when a chan assignment is invalid.
221         //
222         // Per the spec, a value x is assignable to a channel type T if:
223         //  "x is a bidirectional channel value, T is a channel type, x's type V and
224         //  T have identical element types, and at least one of V or T is not a
225         //  defined type."
226         //
227         // Example:
228         //  type T1 chan int
229         //  type T2 chan int
230         //
231         //  var x T1
232         //  // Invalid assignment because both types are named
233         //  var _ T2 = x
234         _InvalidChanAssign
235
236         // _IncompatibleAssign occurs when the type of the right-hand side expression
237         // in an assignment cannot be assigned to the type of the variable being
238         // assigned.
239         //
240         // Example:
241         //  var x []int
242         //  var _ int = x
243         _IncompatibleAssign
244
245         // _UnaddressableFieldAssign occurs when trying to assign to a struct field
246         // in a map value.
247         //
248         // Example:
249         //  func f() {
250         //      m := make(map[string]struct{i int})
251         //      m["foo"].i = 42
252         //  }
253         _UnaddressableFieldAssign
254
255         /* decls > type (+ other type expression codes) */
256
257         // _NotAType occurs when the identifier used as the underlying type in a type
258         // declaration or the right-hand side of a type alias does not denote a type.
259         //
260         // Example:
261         //  var S = 2
262         //
263         //  type T S
264         _NotAType
265
266         // _InvalidArrayLen occurs when an array length is not a constant value.
267         //
268         // Example:
269         //  var n = 3
270         //  var _ = [n]int{}
271         _InvalidArrayLen
272
273         // _BlankIfaceMethod occurs when a method name is '_'.
274         //
275         // Per the spec:
276         //  "The name of each explicitly specified method must be unique and not
277         //  blank."
278         //
279         // Example:
280         //  type T interface {
281         //      _(int)
282         //  }
283         _BlankIfaceMethod
284
285         // _IncomparableMapKey occurs when a map key type does not support the == and
286         // != operators.
287         //
288         // Per the spec:
289         //  "The comparison operators == and != must be fully defined for operands of
290         //  the key type; thus the key type must not be a function, map, or slice."
291         //
292         // Example:
293         //  var x map[T]int
294         //
295         //  type T []int
296         _IncomparableMapKey
297
298         // _InvalidIfaceEmbed occurs when a non-interface type is embedded in an
299         // interface.
300         //
301         // Example:
302         //  type T struct {}
303         //
304         //  func (T) m()
305         //
306         //  type I interface {
307         //      T
308         //  }
309         _InvalidIfaceEmbed
310
311         // _InvalidPtrEmbed occurs when an embedded field is of the pointer form *T,
312         // and T itself is itself a pointer, an unsafe.Pointer, or an interface.
313         //
314         // Per the spec:
315         //  "An embedded field must be specified as a type name T or as a pointer to
316         //  a non-interface type name *T, and T itself may not be a pointer type."
317         //
318         // Example:
319         //  type T *int
320         //
321         //  type S struct {
322         //      *T
323         //  }
324         _InvalidPtrEmbed
325
326         /* decls > func and method */
327
328         // _BadRecv occurs when a method declaration does not have exactly one
329         // receiver parameter.
330         //
331         // Example:
332         //  func () _() {}
333         _BadRecv
334
335         // _InvalidRecv occurs when a receiver type expression is not of the form T
336         // or *T, or T is a pointer type.
337         //
338         // Example:
339         //  type T struct {}
340         //
341         //  func (**T) m() {}
342         _InvalidRecv
343
344         // _DuplicateFieldAndMethod occurs when an identifier appears as both a field
345         // and method name.
346         //
347         // Example:
348         //  type T struct {
349         //      m int
350         //  }
351         //
352         //  func (T) m() {}
353         _DuplicateFieldAndMethod
354
355         // _DuplicateMethod occurs when two methods on the same receiver type have
356         // the same name.
357         //
358         // Example:
359         //  type T struct {}
360         //  func (T) m() {}
361         //  func (T) m(i int) int { return i }
362         _DuplicateMethod
363
364         /* decls > special */
365
366         // _InvalidBlank occurs when a blank identifier is used as a value or type.
367         //
368         // Per the spec:
369         //  "The blank identifier may appear as an operand only on the left-hand side
370         //  of an assignment."
371         //
372         // Example:
373         //  var x = _
374         _InvalidBlank
375
376         // _InvalidIota occurs when the predeclared identifier iota is used outside
377         // of a constant declaration.
378         //
379         // Example:
380         //  var x = iota
381         _InvalidIota
382
383         // _MissingInitBody occurs when an init function is missing its body.
384         //
385         // Example:
386         //  func init()
387         _MissingInitBody
388
389         // _InvalidInitSig occurs when an init function declares parameters or
390         // results.
391         //
392         // Deprecated: no longer emitted by the type checker. _InvalidInitDecl is
393         // used instead.
394         _InvalidInitSig
395
396         // _InvalidInitDecl occurs when init is declared as anything other than a
397         // function.
398         //
399         // Example:
400         //  var init = 1
401         //
402         // Example:
403         //  func init() int { return 1 }
404         _InvalidInitDecl
405
406         // _InvalidMainDecl occurs when main is declared as anything other than a
407         // function, in a main package.
408         _InvalidMainDecl
409
410         /* exprs */
411
412         // _TooManyValues occurs when a function returns too many values for the
413         // expression context in which it is used.
414         //
415         // Example:
416         //  func ReturnTwo() (int, int) {
417         //      return 1, 2
418         //  }
419         //
420         //  var x = ReturnTwo()
421         _TooManyValues
422
423         // _NotAnExpr occurs when a type expression is used where a value expression
424         // is expected.
425         //
426         // Example:
427         //  type T struct {}
428         //
429         //  func f() {
430         //      T
431         //  }
432         _NotAnExpr
433
434         /* exprs > const */
435
436         // _TruncatedFloat occurs when a float constant is truncated to an integer
437         // value.
438         //
439         // Example:
440         //  var _ int = 98.6
441         _TruncatedFloat
442
443         // _NumericOverflow occurs when a numeric constant overflows its target type.
444         //
445         // Example:
446         //  var x int8 = 1000
447         _NumericOverflow
448
449         /* exprs > operation */
450
451         // _UndefinedOp occurs when an operator is not defined for the type(s) used
452         // in an operation.
453         //
454         // Example:
455         //  var c = "a" - "b"
456         _UndefinedOp
457
458         // _MismatchedTypes occurs when operand types are incompatible in a binary
459         // operation.
460         //
461         // Example:
462         //  var a = "hello"
463         //  var b = 1
464         //  var c = a - b
465         _MismatchedTypes
466
467         // _DivByZero occurs when a division operation is provable at compile
468         // time to be a division by zero.
469         //
470         // Example:
471         //  const divisor = 0
472         //  var x int = 1/divisor
473         _DivByZero
474
475         // _NonNumericIncDec occurs when an increment or decrement operator is
476         // applied to a non-numeric value.
477         //
478         // Example:
479         //  func f() {
480         //      var c = "c"
481         //      c++
482         //  }
483         _NonNumericIncDec
484
485         /* exprs > ptr */
486
487         // _UnaddressableOperand occurs when the & operator is applied to an
488         // unaddressable expression.
489         //
490         // Example:
491         //  var x = &1
492         _UnaddressableOperand
493
494         // _InvalidIndirection occurs when a non-pointer value is indirected via the
495         // '*' operator.
496         //
497         // Example:
498         //  var x int
499         //  var y = *x
500         _InvalidIndirection
501
502         /* exprs > [] */
503
504         // _NonIndexableOperand occurs when an index operation is applied to a value
505         // that cannot be indexed.
506         //
507         // Example:
508         //  var x = 1
509         //  var y = x[1]
510         _NonIndexableOperand
511
512         // _InvalidIndex occurs when an index argument is not of integer type,
513         // negative, or out-of-bounds.
514         //
515         // Example:
516         //  var s = [...]int{1,2,3}
517         //  var x = s[5]
518         //
519         // Example:
520         //  var s = []int{1,2,3}
521         //  var _ = s[-1]
522         //
523         // Example:
524         //  var s = []int{1,2,3}
525         //  var i string
526         //  var _ = s[i]
527         _InvalidIndex
528
529         // _SwappedSliceIndices occurs when constant indices in a slice expression
530         // are decreasing in value.
531         //
532         // Example:
533         //  var _ = []int{1,2,3}[2:1]
534         _SwappedSliceIndices
535
536         /* operators > slice */
537
538         // _NonSliceableOperand occurs when a slice operation is applied to a value
539         // whose type is not sliceable, or is unaddressable.
540         //
541         // Example:
542         //  var x = [...]int{1, 2, 3}[:1]
543         //
544         // Example:
545         //  var x = 1
546         //  var y = 1[:1]
547         _NonSliceableOperand
548
549         // _InvalidSliceExpr occurs when a three-index slice expression (a[x:y:z]) is
550         // applied to a string.
551         //
552         // Example:
553         //  var s = "hello"
554         //  var x = s[1:2:3]
555         _InvalidSliceExpr
556
557         /* exprs > shift */
558
559         // _InvalidShiftCount occurs when the right-hand side of a shift operation is
560         // either non-integer, negative, or too large.
561         //
562         // Example:
563         //  var (
564         //      x string
565         //      y int = 1 << x
566         //  )
567         _InvalidShiftCount
568
569         // _InvalidShiftOperand occurs when the shifted operand is not an integer.
570         //
571         // Example:
572         //  var s = "hello"
573         //  var x = s << 2
574         _InvalidShiftOperand
575
576         /* exprs > chan */
577
578         // _InvalidReceive occurs when there is a channel receive from a value that
579         // is either not a channel, or is a send-only channel.
580         //
581         // Example:
582         //  func f() {
583         //      var x = 1
584         //      <-x
585         //  }
586         _InvalidReceive
587
588         // _InvalidSend occurs when there is a channel send to a value that is not a
589         // channel, or is a receive-only channel.
590         //
591         // Example:
592         //  func f() {
593         //      var x = 1
594         //      x <- "hello!"
595         //  }
596         _InvalidSend
597
598         /* exprs > literal */
599
600         // _DuplicateLitKey occurs when an index is duplicated in a slice, array, or
601         // map literal.
602         //
603         // Example:
604         //  var _ = []int{0:1, 0:2}
605         //
606         // Example:
607         //  var _ = map[string]int{"a": 1, "a": 2}
608         _DuplicateLitKey
609
610         // _MissingLitKey occurs when a map literal is missing a key expression.
611         //
612         // Example:
613         //  var _ = map[string]int{1}
614         _MissingLitKey
615
616         // _InvalidLitIndex occurs when the key in a key-value element of a slice or
617         // array literal is not an integer constant.
618         //
619         // Example:
620         //  var i = 0
621         //  var x = []string{i: "world"}
622         _InvalidLitIndex
623
624         // _OversizeArrayLit occurs when an array literal exceeds its length.
625         //
626         // Example:
627         //  var _ = [2]int{1,2,3}
628         _OversizeArrayLit
629
630         // _MixedStructLit occurs when a struct literal contains a mix of positional
631         // and named elements.
632         //
633         // Example:
634         //  var _ = struct{i, j int}{i: 1, 2}
635         _MixedStructLit
636
637         // _InvalidStructLit occurs when a positional struct literal has an incorrect
638         // number of values.
639         //
640         // Example:
641         //  var _ = struct{i, j int}{1,2,3}
642         _InvalidStructLit
643
644         // _MissingLitField occurs when a struct literal refers to a field that does
645         // not exist on the struct type.
646         //
647         // Example:
648         //  var _ = struct{i int}{j: 2}
649         _MissingLitField
650
651         // _DuplicateLitField occurs when a struct literal contains duplicated
652         // fields.
653         //
654         // Example:
655         //  var _ = struct{i int}{i: 1, i: 2}
656         _DuplicateLitField
657
658         // _UnexportedLitField occurs when a positional struct literal implicitly
659         // assigns an unexported field of an imported type.
660         _UnexportedLitField
661
662         // _InvalidLitField occurs when a field name is not a valid identifier.
663         //
664         // Example:
665         //  var _ = struct{i int}{1: 1}
666         _InvalidLitField
667
668         // _UntypedLit occurs when a composite literal omits a required type
669         // identifier.
670         //
671         // Example:
672         //  type outer struct{
673         //      inner struct { i int }
674         //  }
675         //
676         //  var _ = outer{inner: {1}}
677         _UntypedLit
678
679         // _InvalidLit occurs when a composite literal expression does not match its
680         // type.
681         //
682         // Example:
683         //  type P *struct{
684         //      x int
685         //  }
686         //  var _ = P {}
687         _InvalidLit
688
689         /* exprs > selector */
690
691         // _AmbiguousSelector occurs when a selector is ambiguous.
692         //
693         // Example:
694         //  type E1 struct { i int }
695         //  type E2 struct { i int }
696         //  type T struct { E1; E2 }
697         //
698         //  var x T
699         //  var _ = x.i
700         _AmbiguousSelector
701
702         // _UndeclaredImportedName occurs when a package-qualified identifier is
703         // undeclared by the imported package.
704         //
705         // Example:
706         //  import "go/types"
707         //
708         //  var _ = types.NotAnActualIdentifier
709         _UndeclaredImportedName
710
711         // _UnexportedName occurs when a selector refers to an unexported identifier
712         // of an imported package.
713         //
714         // Example:
715         //  import "reflect"
716         //
717         //  type _ reflect.flag
718         _UnexportedName
719
720         // _UndeclaredName occurs when an identifier is not declared in the current
721         // scope.
722         //
723         // Example:
724         //  var x T
725         _UndeclaredName
726
727         // _MissingFieldOrMethod occurs when a selector references a field or method
728         // that does not exist.
729         //
730         // Example:
731         //  type T struct {}
732         //
733         //  var x = T{}.f
734         _MissingFieldOrMethod
735
736         /* exprs > ... */
737
738         // _BadDotDotDotSyntax occurs when a "..." occurs in a context where it is
739         // not valid.
740         //
741         // Example:
742         //  var _ = map[int][...]int{0: {}}
743         _BadDotDotDotSyntax
744
745         // _NonVariadicDotDotDot occurs when a "..." is used on the final argument to
746         // a non-variadic function.
747         //
748         // Example:
749         //  func printArgs(s []string) {
750         //      for _, a := range s {
751         //              println(a)
752         //      }
753         //  }
754         //
755         //  func f() {
756         //      s := []string{"a", "b", "c"}
757         //      printArgs(s...)
758         //  }
759         _NonVariadicDotDotDot
760
761         // _MisplacedDotDotDot occurs when a "..." is used somewhere other than the
762         // final argument in a function declaration.
763         //
764         // Example:
765         //      func f(...int, int)
766         _MisplacedDotDotDot
767
768         // _InvalidDotDotDot occurs when a "..." is used in a non-variadic built-in
769         // function.
770         //
771         // Example:
772         //  var s = []int{1, 2, 3}
773         //  var l = len(s...)
774         _InvalidDotDotDot
775
776         /* exprs > built-in */
777
778         // _UncalledBuiltin occurs when a built-in function is used as a
779         // function-valued expression, instead of being called.
780         //
781         // Per the spec:
782         //  "The built-in functions do not have standard Go types, so they can only
783         //  appear in call expressions; they cannot be used as function values."
784         //
785         // Example:
786         //  var _ = copy
787         _UncalledBuiltin
788
789         // _InvalidAppend occurs when append is called with a first argument that is
790         // not a slice.
791         //
792         // Example:
793         //  var _ = append(1, 2)
794         _InvalidAppend
795
796         // _InvalidCap occurs when an argument to the cap built-in function is not of
797         // supported type.
798         //
799         // See https://golang.org/ref/spec#Length_and_capacity for information on
800         // which underlying types are supported as arguments to cap and len.
801         //
802         // Example:
803         //  var s = 2
804         //  var x = cap(s)
805         _InvalidCap
806
807         // _InvalidClose occurs when close(...) is called with an argument that is
808         // not of channel type, or that is a receive-only channel.
809         //
810         // Example:
811         //  func f() {
812         //      var x int
813         //      close(x)
814         //  }
815         _InvalidClose
816
817         // _InvalidCopy occurs when the arguments are not of slice type or do not
818         // have compatible type.
819         //
820         // See https://golang.org/ref/spec#Appending_and_copying_slices for more
821         // information on the type requirements for the copy built-in.
822         //
823         // Example:
824         //  func f() {
825         //      var x []int
826         //      y := []int64{1,2,3}
827         //      copy(x, y)
828         //  }
829         _InvalidCopy
830
831         // _InvalidComplex occurs when the complex built-in function is called with
832         // arguments with incompatible types.
833         //
834         // Example:
835         //  var _ = complex(float32(1), float64(2))
836         _InvalidComplex
837
838         // _InvalidDelete occurs when the delete built-in function is called with a
839         // first argument that is not a map.
840         //
841         // Example:
842         //  func f() {
843         //      m := "hello"
844         //      delete(m, "e")
845         //  }
846         _InvalidDelete
847
848         // _InvalidImag occurs when the imag built-in function is called with an
849         // argument that does not have complex type.
850         //
851         // Example:
852         //  var _ = imag(int(1))
853         _InvalidImag
854
855         // _InvalidLen occurs when an argument to the len built-in function is not of
856         // supported type.
857         //
858         // See https://golang.org/ref/spec#Length_and_capacity for information on
859         // which underlying types are supported as arguments to cap and len.
860         //
861         // Example:
862         //  var s = 2
863         //  var x = len(s)
864         _InvalidLen
865
866         // _SwappedMakeArgs occurs when make is called with three arguments, and its
867         // length argument is larger than its capacity argument.
868         //
869         // Example:
870         //  var x = make([]int, 3, 2)
871         _SwappedMakeArgs
872
873         // _InvalidMake occurs when make is called with an unsupported type argument.
874         //
875         // See https://golang.org/ref/spec#Making_slices_maps_and_channels for
876         // information on the types that may be created using make.
877         //
878         // Example:
879         //  var x = make(int)
880         _InvalidMake
881
882         // _InvalidReal occurs when the real built-in function is called with an
883         // argument that does not have complex type.
884         //
885         // Example:
886         //  var _ = real(int(1))
887         _InvalidReal
888
889         /* exprs > assertion */
890
891         // _InvalidAssert occurs when a type assertion is applied to a
892         // value that is not of interface type.
893         //
894         // Example:
895         //  var x = 1
896         //  var _ = x.(float64)
897         _InvalidAssert
898
899         // _ImpossibleAssert occurs for a type assertion x.(T) when the value x of
900         // interface cannot have dynamic type T, due to a missing or mismatching
901         // method on T.
902         //
903         // Example:
904         //  type T int
905         //
906         //  func (t *T) m() int { return int(*t) }
907         //
908         //  type I interface { m() int }
909         //
910         //  var x I
911         //  var _ = x.(T)
912         _ImpossibleAssert
913
914         /* exprs > conversion */
915
916         // _InvalidConversion occurs when the argument type cannot be converted to the
917         // target.
918         //
919         // See https://golang.org/ref/spec#Conversions for the rules of
920         // convertibility.
921         //
922         // Example:
923         //  var x float64
924         //  var _ = string(x)
925         _InvalidConversion
926
927         // _InvalidUntypedConversion occurs when an there is no valid implicit
928         // conversion from an untyped value satisfying the type constraints of the
929         // context in which it is used.
930         //
931         // Example:
932         //  var _ = 1 + ""
933         _InvalidUntypedConversion
934
935         /* offsetof */
936
937         // _BadOffsetofSyntax occurs when unsafe.Offsetof is called with an argument
938         // that is not a selector expression.
939         //
940         // Example:
941         //  import "unsafe"
942         //
943         //  var x int
944         //  var _ = unsafe.Offsetof(x)
945         _BadOffsetofSyntax
946
947         // _InvalidOffsetof occurs when unsafe.Offsetof is called with a method
948         // selector, rather than a field selector, or when the field is embedded via
949         // a pointer.
950         //
951         // Per the spec:
952         //
953         //  "If f is an embedded field, it must be reachable without pointer
954         //  indirections through fields of the struct. "
955         //
956         // Example:
957         //  import "unsafe"
958         //
959         //  type T struct { f int }
960         //  type S struct { *T }
961         //  var s S
962         //  var _ = unsafe.Offsetof(s.f)
963         //
964         // Example:
965         //  import "unsafe"
966         //
967         //  type S struct{}
968         //
969         //  func (S) m() {}
970         //
971         //  var s S
972         //  var _ = unsafe.Offsetof(s.m)
973         _InvalidOffsetof
974
975         /* control flow > scope */
976
977         // _UnusedExpr occurs when a side-effect free expression is used as a
978         // statement. Such a statement has no effect.
979         //
980         // Example:
981         //  func f(i int) {
982         //      i*i
983         //  }
984         _UnusedExpr
985
986         // _UnusedVar occurs when a variable is declared but unused.
987         //
988         // Example:
989         //  func f() {
990         //      x := 1
991         //  }
992         _UnusedVar
993
994         // _MissingReturn occurs when a function with results is missing a return
995         // statement.
996         //
997         // Example:
998         //  func f() int {}
999         _MissingReturn
1000
1001         // _WrongResultCount occurs when a return statement returns an incorrect
1002         // number of values.
1003         //
1004         // Example:
1005         //  func ReturnOne() int {
1006         //      return 1, 2
1007         //  }
1008         _WrongResultCount
1009
1010         // _OutOfScopeResult occurs when the name of a value implicitly returned by
1011         // an empty return statement is shadowed in a nested scope.
1012         //
1013         // Example:
1014         //  func factor(n int) (i int) {
1015         //      for i := 2; i < n; i++ {
1016         //              if n%i == 0 {
1017         //                      return
1018         //              }
1019         //      }
1020         //      return 0
1021         //  }
1022         _OutOfScopeResult
1023
1024         /* control flow > if */
1025
1026         // _InvalidCond occurs when an if condition is not a boolean expression.
1027         //
1028         // Example:
1029         //  func checkReturn(i int) {
1030         //      if i {
1031         //              panic("non-zero return")
1032         //      }
1033         //  }
1034         _InvalidCond
1035
1036         /* control flow > for */
1037
1038         // _InvalidPostDecl occurs when there is a declaration in a for-loop post
1039         // statement.
1040         //
1041         // Example:
1042         //  func f() {
1043         //      for i := 0; i < 10; j := 0 {}
1044         //  }
1045         _InvalidPostDecl
1046
1047         // _InvalidIterVar occurs when two iteration variables are used while ranging
1048         // over a channel.
1049         //
1050         // Example:
1051         //  func f(c chan int) {
1052         //      for k, v := range c {
1053         //              println(k, v)
1054         //      }
1055         //  }
1056         _InvalidIterVar
1057
1058         // _InvalidRangeExpr occurs when the type of a range expression is not array,
1059         // slice, string, map, or channel.
1060         //
1061         // Example:
1062         //  func f(i int) {
1063         //      for j := range i {
1064         //              println(j)
1065         //      }
1066         //  }
1067         _InvalidRangeExpr
1068
1069         /* control flow > switch */
1070
1071         // _MisplacedBreak occurs when a break statement is not within a for, switch,
1072         // or select statement of the innermost function definition.
1073         //
1074         // Example:
1075         //  func f() {
1076         //      break
1077         //  }
1078         _MisplacedBreak
1079
1080         // _MisplacedContinue occurs when a continue statement is not within a for
1081         // loop of the innermost function definition.
1082         //
1083         // Example:
1084         //  func sumeven(n int) int {
1085         //      proceed := func() {
1086         //              continue
1087         //      }
1088         //      sum := 0
1089         //      for i := 1; i <= n; i++ {
1090         //              if i % 2 != 0 {
1091         //                      proceed()
1092         //              }
1093         //              sum += i
1094         //      }
1095         //      return sum
1096         //  }
1097         _MisplacedContinue
1098
1099         // _MisplacedFallthrough occurs when a fallthrough statement is not within an
1100         // expression switch.
1101         //
1102         // Example:
1103         //  func typename(i interface{}) string {
1104         //      switch i.(type) {
1105         //      case int64:
1106         //              fallthrough
1107         //      case int:
1108         //              return "int"
1109         //      }
1110         //      return "unsupported"
1111         //  }
1112         _MisplacedFallthrough
1113
1114         // _DuplicateCase occurs when a type or expression switch has duplicate
1115         // cases.
1116         //
1117         // Example:
1118         //  func printInt(i int) {
1119         //      switch i {
1120         //      case 1:
1121         //              println("one")
1122         //      case 1:
1123         //              println("One")
1124         //      }
1125         //  }
1126         _DuplicateCase
1127
1128         // _DuplicateDefault occurs when a type or expression switch has multiple
1129         // default clauses.
1130         //
1131         // Example:
1132         //  func printInt(i int) {
1133         //      switch i {
1134         //      case 1:
1135         //              println("one")
1136         //      default:
1137         //              println("One")
1138         //      default:
1139         //              println("1")
1140         //      }
1141         //  }
1142         _DuplicateDefault
1143
1144         // _BadTypeKeyword occurs when a .(type) expression is used anywhere other
1145         // than a type switch.
1146         //
1147         // Example:
1148         //  type I interface {
1149         //      m()
1150         //  }
1151         //  var t I
1152         //  var _ = t.(type)
1153         _BadTypeKeyword
1154
1155         // _InvalidTypeSwitch occurs when .(type) is used on an expression that is
1156         // not of interface type.
1157         //
1158         // Example:
1159         //  func f(i int) {
1160         //      switch x := i.(type) {}
1161         //  }
1162         _InvalidTypeSwitch
1163
1164         // _InvalidExprSwitch occurs when a switch expression is not comparable.
1165         //
1166         // Example:
1167         //  func _() {
1168         //      var a struct{ _ func() }
1169         //      switch a /* ERROR cannot switch on a */ {
1170         //      }
1171         //  }
1172         _InvalidExprSwitch
1173
1174         /* control flow > select */
1175
1176         // _InvalidSelectCase occurs when a select case is not a channel send or
1177         // receive.
1178         //
1179         // Example:
1180         //  func checkChan(c <-chan int) bool {
1181         //      select {
1182         //      case c:
1183         //              return true
1184         //      default:
1185         //              return false
1186         //      }
1187         //  }
1188         _InvalidSelectCase
1189
1190         /* control flow > labels and jumps */
1191
1192         // _UndeclaredLabel occurs when an undeclared label is jumped to.
1193         //
1194         // Example:
1195         //  func f() {
1196         //      goto L
1197         //  }
1198         _UndeclaredLabel
1199
1200         // _DuplicateLabel occurs when a label is declared more than once.
1201         //
1202         // Example:
1203         //  func f() int {
1204         //  L:
1205         //  L:
1206         //      return 1
1207         //  }
1208         _DuplicateLabel
1209
1210         // _MisplacedLabel occurs when a break or continue label is not on a for,
1211         // switch, or select statement.
1212         //
1213         // Example:
1214         //  func f() {
1215         //  L:
1216         //      a := []int{1,2,3}
1217         //      for _, e := range a {
1218         //              if e > 10 {
1219         //                      break L
1220         //              }
1221         //              println(a)
1222         //      }
1223         //  }
1224         _MisplacedLabel
1225
1226         // _UnusedLabel occurs when a label is declared but not used.
1227         //
1228         // Example:
1229         //  func f() {
1230         //  L:
1231         //  }
1232         _UnusedLabel
1233
1234         // _JumpOverDecl occurs when a label jumps over a variable declaration.
1235         //
1236         // Example:
1237         //  func f() int {
1238         //      goto L
1239         //      x := 2
1240         //  L:
1241         //      x++
1242         //      return x
1243         //  }
1244         _JumpOverDecl
1245
1246         // _JumpIntoBlock occurs when a forward jump goes to a label inside a nested
1247         // block.
1248         //
1249         // Example:
1250         //  func f(x int) {
1251         //      goto L
1252         //      if x > 0 {
1253         //      L:
1254         //              print("inside block")
1255         //      }
1256         // }
1257         _JumpIntoBlock
1258
1259         /* control flow > calls */
1260
1261         // _InvalidMethodExpr occurs when a pointer method is called but the argument
1262         // is not addressable.
1263         //
1264         // Example:
1265         //  type T struct {}
1266         //
1267         //  func (*T) m() int { return 1 }
1268         //
1269         //  var _ = T.m(T{})
1270         _InvalidMethodExpr
1271
1272         // _WrongArgCount occurs when too few or too many arguments are passed by a
1273         // function call.
1274         //
1275         // Example:
1276         //  func f(i int) {}
1277         //  var x = f()
1278         _WrongArgCount
1279
1280         // _InvalidCall occurs when an expression is called that is not of function
1281         // type.
1282         //
1283         // Example:
1284         //  var x = "x"
1285         //  var y = x()
1286         _InvalidCall
1287
1288         /* control flow > suspended */
1289
1290         // _UnusedResults occurs when a restricted expression-only built-in function
1291         // is suspended via go or defer. Such a suspension discards the results of
1292         // these side-effect free built-in functions, and therefore is ineffectual.
1293         //
1294         // Example:
1295         //  func f(a []int) int {
1296         //      defer len(a)
1297         //      return i
1298         //  }
1299         _UnusedResults
1300
1301         // _InvalidDefer occurs when a deferred expression is not a function call,
1302         // for example if the expression is a type conversion.
1303         //
1304         // Example:
1305         //  func f(i int) int {
1306         //      defer int32(i)
1307         //      return i
1308         //  }
1309         _InvalidDefer
1310
1311         // _InvalidGo occurs when a go expression is not a function call, for example
1312         // if the expression is a type conversion.
1313         //
1314         // Example:
1315         //  func f(i int) int {
1316         //      go int32(i)
1317         //      return i
1318         //  }
1319         _InvalidGo
1320
1321         // _BadDecl occurs when a declaration has invalid syntax.
1322         _BadDecl
1323
1324         // _Todo is a placeholder for error codes that have not been decided.
1325         // TODO(rFindley) remove this error code after deciding on errors for generics code.
1326         _Todo
1327 )