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