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
5package types
6
7type 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
31const (
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	// Example:
390	//  func init() int { return 1 }
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	_InvalidInitDecl
399
400	// _InvalidMainDecl occurs when main is declared as anything other than a
401	// function, in a main package.
402	_InvalidMainDecl
403
404	/* exprs */
405
406	// _TooManyValues occurs when a function returns too many values for the
407	// expression context in which it is used.
408	//
409	// Example:
410	//  func ReturnTwo() (int, int) {
411	//  	return 1, 2
412	//  }
413	//
414	//  var x = ReturnTwo()
415	_TooManyValues
416
417	// _NotAnExpr occurs when a type expression is used where a value expression
418	// is expected.
419	//
420	// Example:
421	//  type T struct {}
422	//
423	//  func f() {
424	//  	T
425	//  }
426	_NotAnExpr
427
428	/* exprs > const */
429
430	// _TruncatedFloat occurs when a float constant is truncated to an integer
431	// value.
432	//
433	// Example:
434	//  var _ int = 98.6
435	_TruncatedFloat
436
437	// _NumericOverflow occurs when a numeric constant overflows its target type.
438	//
439	// Example:
440	//  var x int8 = 1000
441	_NumericOverflow
442
443	/* exprs > operation */
444
445	// _UndefinedOp occurs when an operator is not defined for the type(s) used
446	// in an operation.
447	//
448	// Example:
449	//  var c = "a" - "b"
450	_UndefinedOp
451
452	// _MismatchedTypes occurs when operand types are incompatible in a binary
453	// operation.
454	//
455	// Example:
456	//  var a = "hello"
457	//  var b = 1
458	//  var c = a - b
459	_MismatchedTypes
460
461	// _DivByZero occurs when a division operation is provable at compile
462	// time to be a division by zero.
463	//
464	// Example:
465	//  const divisor = 0
466	//  var x int = 1/divisor
467	_DivByZero
468
469	// _NonNumericIncDec occurs when an increment or decrement operator is
470	// applied to a non-numeric value.
471	//
472	// Example:
473	//  func f() {
474	//  	var c = "c"
475	//  	c++
476	//  }
477	_NonNumericIncDec
478
479	/* exprs > ptr */
480
481	// _UnaddressableOperand occurs when the & operator is applied to an
482	// unaddressable expression.
483	//
484	// Example:
485	//  var x = &1
486	_UnaddressableOperand
487
488	// _InvalidIndirection occurs when a non-pointer value is indirected via the
489	// '*' operator.
490	//
491	// Example:
492	//  var x int
493	//  var y = *x
494	_InvalidIndirection
495
496	/* exprs > [] */
497
498	// _NonIndexableOperand occurs when an index operation is applied to a value
499	// that cannot be indexed.
500	//
501	// Example:
502	//  var x = 1
503	//  var y = x[1]
504	_NonIndexableOperand
505
506	// _InvalidIndex occurs when an index argument is not of integer type,
507	// negative, or out-of-bounds.
508	//
509	// Example:
510	//  var s = [...]int{1,2,3}
511	//  var x = s[5]
512	//
513	// Example:
514	//  var s = []int{1,2,3}
515	//  var _ = s[-1]
516	//
517	// Example:
518	//  var s = []int{1,2,3}
519	//  var i string
520	//  var _ = s[i]
521	_InvalidIndex
522
523	// _SwappedSliceIndices occurs when constant indices in a slice expression
524	// are decreasing in value.
525	//
526	// Example:
527	//  var _ = []int{1,2,3}[2:1]
528	_SwappedSliceIndices
529
530	/* operators > slice */
531
532	// _NonSliceableOperand occurs when a slice operation is applied to a value
533	// whose type is not sliceable, or is unaddressable.
534	//
535	// Example:
536	//  var x = [...]int{1, 2, 3}[:1]
537	//
538	// Example:
539	//  var x = 1
540	//  var y = 1[:1]
541	_NonSliceableOperand
542
543	// _InvalidSliceExpr occurs when a three-index slice expression (a[x:y:z]) is
544	// applied to a string.
545	//
546	// Example:
547	//  var s = "hello"
548	//  var x = s[1:2:3]
549	_InvalidSliceExpr
550
551	/* exprs > shift */
552
553	// _InvalidShiftCount occurs when the right-hand side of a shift operation is
554	// either non-integer, negative, or too large.
555	//
556	// Example:
557	//  var (
558	//  	x string
559	//  	y int = 1 << x
560	//  )
561	_InvalidShiftCount
562
563	// _InvalidShiftOperand occurs when the shifted operand is not an integer.
564	//
565	// Example:
566	//  var s = "hello"
567	//  var x = s << 2
568	_InvalidShiftOperand
569
570	/* exprs > chan */
571
572	// _InvalidReceive occurs when there is a channel receive from a value that
573	// is either not a channel, or is a send-only channel.
574	//
575	// Example:
576	//  func f() {
577	//  	var x = 1
578	//  	<-x
579	//  }
580	_InvalidReceive
581
582	// _InvalidSend occurs when there is a channel send to a value that is not a
583	// channel, or is a receive-only channel.
584	//
585	// Example:
586	//  func f() {
587	//  	var x = 1
588	//  	x <- "hello!"
589	//  }
590	_InvalidSend
591
592	/* exprs > literal */
593
594	// _DuplicateLitKey occurs when an index is duplicated in a slice, array, or
595	// map literal.
596	//
597	// Example:
598	//  var _ = []int{0:1, 0:2}
599	//
600	// Example:
601	//  var _ = map[string]int{"a": 1, "a": 2}
602	_DuplicateLitKey
603
604	// _MissingLitKey occurs when a map literal is missing a key expression.
605	//
606	// Example:
607	//  var _ = map[string]int{1}
608	_MissingLitKey
609
610	// _InvalidLitIndex occurs when the key in a key-value element of a slice or
611	// array literal is not an integer constant.
612	//
613	// Example:
614	//  var i = 0
615	//  var x = []string{i: "world"}
616	_InvalidLitIndex
617
618	// _OversizeArrayLit occurs when an array literal exceeds its length.
619	//
620	// Example:
621	//  var _ = [2]int{1,2,3}
622	_OversizeArrayLit
623
624	// _MixedStructLit occurs when a struct literal contains a mix of positional
625	// and named elements.
626	//
627	// Example:
628	//  var _ = struct{i, j int}{i: 1, 2}
629	_MixedStructLit
630
631	// _InvalidStructLit occurs when a positional struct literal has an incorrect
632	// number of values.
633	//
634	// Example:
635	//  var _ = struct{i, j int}{1,2,3}
636	_InvalidStructLit
637
638	// _MissingLitField occurs when a struct literal refers to a field that does
639	// not exist on the struct type.
640	//
641	// Example:
642	//  var _ = struct{i int}{j: 2}
643	_MissingLitField
644
645	// _DuplicateLitField occurs when a struct literal contains duplicated
646	// fields.
647	//
648	// Example:
649	//  var _ = struct{i int}{i: 1, i: 2}
650	_DuplicateLitField
651
652	// _UnexportedLitField occurs when a positional struct literal implicitly
653	// assigns an unexported field of an imported type.
654	_UnexportedLitField
655
656	// _InvalidLitField occurs when a field name is not a valid identifier.
657	//
658	// Example:
659	//  var _ = struct{i int}{1: 1}
660	_InvalidLitField
661
662	// _UntypedLit occurs when a composite literal omits a required type
663	// identifier.
664	//
665	// Example:
666	//  type outer struct{
667	//  	inner struct { i int }
668	//  }
669	//
670	//  var _ = outer{inner: {1}}
671	_UntypedLit
672
673	// _InvalidLit occurs when a composite literal expression does not match its
674	// type.
675	//
676	// Example:
677	//  type P *struct{
678	//  	x int
679	//  }
680	//  var _ = P {}
681	_InvalidLit
682
683	/* exprs > selector */
684
685	// _AmbiguousSelector occurs when a selector is ambiguous.
686	//
687	// Example:
688	//  type E1 struct { i int }
689	//  type E2 struct { i int }
690	//  type T struct { E1; E2 }
691	//
692	//  var x T
693	//  var _ = x.i
694	_AmbiguousSelector
695
696	// _UndeclaredImportedName occurs when a package-qualified identifier is
697	// undeclared by the imported package.
698	//
699	// Example:
700	//  import "go/types"
701	//
702	//  var _ = types.NotAnActualIdentifier
703	_UndeclaredImportedName
704
705	// _UnexportedName occurs when a selector refers to an unexported identifier
706	// of an imported package.
707	//
708	// Example:
709	//  import "reflect"
710	//
711	//  type _ reflect.flag
712	_UnexportedName
713
714	// _UndeclaredName occurs when an identifier is not declared in the current
715	// scope.
716	//
717	// Example:
718	//  var x T
719	_UndeclaredName
720
721	// _MissingFieldOrMethod occurs when a selector references a field or method
722	// that does not exist.
723	//
724	// Example:
725	//  type T struct {}
726	//
727	//  var x = T{}.f
728	_MissingFieldOrMethod
729
730	/* exprs > ... */
731
732	// _BadDotDotDotSyntax occurs when a "..." occurs in a context where it is
733	// not valid.
734	//
735	// Example:
736	//  var _ = map[int][...]int{0: {}}
737	_BadDotDotDotSyntax
738
739	// _NonVariadicDotDotDot occurs when a "..." is used on the final argument to
740	// a non-variadic function.
741	//
742	// Example:
743	//  func printArgs(s []string) {
744	//  	for _, a := range s {
745	//  		println(a)
746	//  	}
747	//  }
748	//
749	//  func f() {
750	//  	s := []string{"a", "b", "c"}
751	//  	printArgs(s...)
752	//  }
753	_NonVariadicDotDotDot
754
755	// _MisplacedDotDotDot occurs when a "..." is used somewhere other than the
756	// final argument to a function call.
757	//
758	// Example:
759	//  func printArgs(args ...int) {
760	//  	for _, a := range args {
761	//  		println(a)
762	//  	}
763	//  }
764	//
765	//  func f() {
766	//  	a := []int{1,2,3}
767	//  	printArgs(0, a...)
768	//  }
769	_MisplacedDotDotDot
770
771	// _InvalidDotDotDotOperand occurs when a "..." operator is applied to a
772	// single-valued operand.
773	//
774	// Example:
775	//  func printArgs(args ...int) {
776	//  	for _, a := range args {
777	//  		println(a)
778	//  	}
779	//  }
780	//
781	//  func f() {
782	//  	a := 1
783	//  	printArgs(a...)
784	//  }
785	//
786	// Example:
787	//  func args() (int, int) {
788	//  	return 1, 2
789	//  }
790	//
791	//  func printArgs(args ...int) {
792	//  	for _, a := range args {
793	//  		println(a)
794	//  	}
795	//  }
796	//
797	//  func g() {
798	//  	printArgs(args()...)
799	//  }
800	_InvalidDotDotDotOperand
801
802	// _InvalidDotDotDot occurs when a "..." is used in a non-variadic built-in
803	// function.
804	//
805	// Example:
806	//  var s = []int{1, 2, 3}
807	//  var l = len(s...)
808	_InvalidDotDotDot
809
810	/* exprs > built-in */
811
812	// _UncalledBuiltin occurs when a built-in function is used as a
813	// function-valued expression, instead of being called.
814	//
815	// Per the spec:
816	//  "The built-in functions do not have standard Go types, so they can only
817	//  appear in call expressions; they cannot be used as function values."
818	//
819	// Example:
820	//  var _ = copy
821	_UncalledBuiltin
822
823	// _InvalidAppend occurs when append is called with a first argument that is
824	// not a slice.
825	//
826	// Example:
827	//  var _ = append(1, 2)
828	_InvalidAppend
829
830	// _InvalidCap occurs when an argument to the cap built-in function is not of
831	// supported type.
832	//
833	// See https://golang.org/ref/spec#Length_and_capacity for information on
834	// which underlying types are supported as arguments to cap and len.
835	//
836	// Example:
837	//  var s = 2
838	//  var x = cap(s)
839	_InvalidCap
840
841	// _InvalidClose occurs when close(...) is called with an argument that is
842	// not of channel type, or that is a receive-only channel.
843	//
844	// Example:
845	//  func f() {
846	//  	var x int
847	//  	close(x)
848	//  }
849	_InvalidClose
850
851	// _InvalidCopy occurs when the arguments are not of slice type or do not
852	// have compatible type.
853	//
854	// See https://golang.org/ref/spec#Appending_and_copying_slices for more
855	// information on the type requirements for the copy built-in.
856	//
857	// Example:
858	//  func f() {
859	//  	var x []int
860	//  	y := []int64{1,2,3}
861	//  	copy(x, y)
862	//  }
863	_InvalidCopy
864
865	// _InvalidComplex occurs when the complex built-in function is called with
866	// arguments with incompatible types.
867	//
868	// Example:
869	//  var _ = complex(float32(1), float64(2))
870	_InvalidComplex
871
872	// _InvalidDelete occurs when the delete built-in function is called with a
873	// first argument that is not a map.
874	//
875	// Example:
876	//  func f() {
877	//  	m := "hello"
878	//  	delete(m, "e")
879	//  }
880	_InvalidDelete
881
882	// _InvalidImag occurs when the imag built-in function is called with an
883	// argument that does not have complex type.
884	//
885	// Example:
886	//  var _ = imag(int(1))
887	_InvalidImag
888
889	// _InvalidLen occurs when an argument to the len built-in function is not of
890	// supported type.
891	//
892	// See https://golang.org/ref/spec#Length_and_capacity for information on
893	// which underlying types are supported as arguments to cap and len.
894	//
895	// Example:
896	//  var s = 2
897	//  var x = len(s)
898	_InvalidLen
899
900	// _SwappedMakeArgs occurs when make is called with three arguments, and its
901	// length argument is larger than its capacity argument.
902	//
903	// Example:
904	//  var x = make([]int, 3, 2)
905	_SwappedMakeArgs
906
907	// _InvalidMake occurs when make is called with an unsupported type argument.
908	//
909	// See https://golang.org/ref/spec#Making_slices_maps_and_channels for
910	// information on the types that may be created using make.
911	//
912	// Example:
913	//  var x = make(int)
914	_InvalidMake
915
916	// _InvalidReal occurs when the real built-in function is called with an
917	// argument that does not have complex type.
918	//
919	// Example:
920	//  var _ = real(int(1))
921	_InvalidReal
922
923	/* exprs > assertion */
924
925	// _InvalidAssert occurs when a type assertion is applied to a
926	// value that is not of interface type.
927	//
928	// Example:
929	//  var x = 1
930	//  var _ = x.(float64)
931	_InvalidAssert
932
933	// _ImpossibleAssert occurs for a type assertion x.(T) when the value x of
934	// interface cannot have dynamic type T, due to a missing or mismatching
935	// method on T.
936	//
937	// Example:
938	//  type T int
939	//
940	//  func (t *T) m() int { return int(*t) }
941	//
942	//  type I interface { m() int }
943	//
944	//  var x I
945	//  var _ = x.(T)
946	_ImpossibleAssert
947
948	/* exprs > conversion */
949
950	// _InvalidConversion occurs when the argument type cannot be converted to the
951	// target.
952	//
953	// See https://golang.org/ref/spec#Conversions for the rules of
954	// convertibility.
955	//
956	// Example:
957	//  var x float64
958	//  var _ = string(x)
959	_InvalidConversion
960
961	// _InvalidUntypedConversion occurs when an there is no valid implicit
962	// conversion from an untyped value satisfying the type constraints of the
963	// context in which it is used.
964	//
965	// Example:
966	//  var _ = 1 + ""
967	_InvalidUntypedConversion
968
969	/* offsetof */
970
971	// _BadOffsetofSyntax occurs when unsafe.Offsetof is called with an argument
972	// that is not a selector expression.
973	//
974	// Example:
975	//  import "unsafe"
976	//
977	//  var x int
978	//  var _ = unsafe.Offsetof(x)
979	_BadOffsetofSyntax
980
981	// _InvalidOffsetof occurs when unsafe.Offsetof is called with a method
982	// selector, rather than a field selector, or when the field is embedded via
983	// a pointer.
984	//
985	// Per the spec:
986	//
987	//  "If f is an embedded field, it must be reachable without pointer
988	//  indirections through fields of the struct. "
989	//
990	// Example:
991	//  import "unsafe"
992	//
993	//  type T struct { f int }
994	//  type S struct { *T }
995	//  var s S
996	//  var _ = unsafe.Offsetof(s.f)
997	//
998	// Example:
999	//  import "unsafe"
1000	//
1001	//  type S struct{}
1002	//
1003	//  func (S) m() {}
1004	//
1005	//  var s S
1006	//  var _ = unsafe.Offsetof(s.m)
1007	_InvalidOffsetof
1008
1009	/* control flow > scope */
1010
1011	// _UnusedExpr occurs when a side-effect free expression is used as a
1012	// statement. Such a statement has no effect.
1013	//
1014	// Example:
1015	//  func f(i int) {
1016	//  	i*i
1017	//  }
1018	_UnusedExpr
1019
1020	// _UnusedVar occurs when a variable is declared but unused.
1021	//
1022	// Example:
1023	//  func f() {
1024	//  	x := 1
1025	//  }
1026	_UnusedVar
1027
1028	// _MissingReturn occurs when a function with results is missing a return
1029	// statement.
1030	//
1031	// Example:
1032	//  func f() int {}
1033	_MissingReturn
1034
1035	// _WrongResultCount occurs when a return statement returns an incorrect
1036	// number of values.
1037	//
1038	// Example:
1039	//  func ReturnOne() int {
1040	//  	return 1, 2
1041	//  }
1042	_WrongResultCount
1043
1044	// _OutOfScopeResult occurs when the name of a value implicitly returned by
1045	// an empty return statement is shadowed in a nested scope.
1046	//
1047	// Example:
1048	//  func factor(n int) (i int) {
1049	//  	for i := 2; i < n; i++ {
1050	//  		if n%i == 0 {
1051	//  			return
1052	//  		}
1053	//  	}
1054	//  	return 0
1055	//  }
1056	_OutOfScopeResult
1057
1058	/* control flow > if */
1059
1060	// _InvalidCond occurs when an if condition is not a boolean expression.
1061	//
1062	// Example:
1063	//  func checkReturn(i int) {
1064	//  	if i {
1065	//  		panic("non-zero return")
1066	//  	}
1067	//  }
1068	_InvalidCond
1069
1070	/* control flow > for */
1071
1072	// _InvalidPostDecl occurs when there is a declaration in a for-loop post
1073	// statement.
1074	//
1075	// Example:
1076	//  func f() {
1077	//  	for i := 0; i < 10; j := 0 {}
1078	//  }
1079	_InvalidPostDecl
1080
1081	// _InvalidChanRange occurs when a send-only channel used in a range
1082	// expression.
1083	//
1084	// Example:
1085	//  func sum(c chan<- int) {
1086	//  	s := 0
1087	//  	for i := range c {
1088	//  		s += i
1089	//  	}
1090	//  }
1091	_InvalidChanRange
1092
1093	// _InvalidIterVar occurs when two iteration variables are used while ranging
1094	// over a channel.
1095	//
1096	// Example:
1097	//  func f(c chan int) {
1098	//  	for k, v := range c {
1099	//  		println(k, v)
1100	//  	}
1101	//  }
1102	_InvalidIterVar
1103
1104	// _InvalidRangeExpr occurs when the type of a range expression is not array,
1105	// slice, string, map, or channel.
1106	//
1107	// Example:
1108	//  func f(i int) {
1109	//  	for j := range i {
1110	//  		println(j)
1111	//  	}
1112	//  }
1113	_InvalidRangeExpr
1114
1115	/* control flow > switch */
1116
1117	// _MisplacedBreak occurs when a break statement is not within a for, switch,
1118	// or select statement of the innermost function definition.
1119	//
1120	// Example:
1121	//  func f() {
1122	//  	break
1123	//  }
1124	_MisplacedBreak
1125
1126	// _MisplacedContinue occurs when a continue statement is not within a for
1127	// loop of the innermost function definition.
1128	//
1129	// Example:
1130	//  func sumeven(n int) int {
1131	//  	proceed := func() {
1132	//  		continue
1133	//  	}
1134	//  	sum := 0
1135	//  	for i := 1; i <= n; i++ {
1136	//  		if i % 2 != 0 {
1137	//  			proceed()
1138	//  		}
1139	//  		sum += i
1140	//  	}
1141	//  	return sum
1142	//  }
1143	_MisplacedContinue
1144
1145	// _MisplacedFallthrough occurs when a fallthrough statement is not within an
1146	// expression switch.
1147	//
1148	// Example:
1149	//  func typename(i interface{}) string {
1150	//  	switch i.(type) {
1151	//  	case int64:
1152	//  		fallthrough
1153	//  	case int:
1154	//  		return "int"
1155	//  	}
1156	//  	return "unsupported"
1157	//  }
1158	_MisplacedFallthrough
1159
1160	// _DuplicateCase occurs when a type or expression switch has duplicate
1161	// cases.
1162	//
1163	// Example:
1164	//  func printInt(i int) {
1165	//  	switch i {
1166	//  	case 1:
1167	//  		println("one")
1168	//  	case 1:
1169	//  		println("One")
1170	//  	}
1171	//  }
1172	_DuplicateCase
1173
1174	// _DuplicateDefault occurs when a type or expression switch has multiple
1175	// default clauses.
1176	//
1177	// Example:
1178	//  func printInt(i int) {
1179	//  	switch i {
1180	//  	case 1:
1181	//  		println("one")
1182	//  	default:
1183	//  		println("One")
1184	//  	default:
1185	//  		println("1")
1186	//  	}
1187	//  }
1188	_DuplicateDefault
1189
1190	// _BadTypeKeyword occurs when a .(type) expression is used anywhere other
1191	// than a type switch.
1192	//
1193	// Example:
1194	//  type I interface {
1195	//  	m()
1196	//  }
1197	//  var t I
1198	//  var _ = t.(type)
1199	_BadTypeKeyword
1200
1201	// _InvalidTypeSwitch occurs when .(type) is used on an expression that is
1202	// not of interface type.
1203	//
1204	// Example:
1205	//  func f(i int) {
1206	//  	switch x := i.(type) {}
1207	//  }
1208	_InvalidTypeSwitch
1209
1210	// _InvalidExprSwitch occurs when a switch expression is not comparable.
1211	//
1212	// Example:
1213	//  func _() {
1214	//  	var a struct{ _ func() }
1215	//  	switch a /* ERROR cannot switch on a */ {
1216	//  	}
1217	//  }
1218	_InvalidExprSwitch
1219
1220	/* control flow > select */
1221
1222	// _InvalidSelectCase occurs when a select case is not a channel send or
1223	// receive.
1224	//
1225	// Example:
1226	//  func checkChan(c <-chan int) bool {
1227	//  	select {
1228	//  	case c:
1229	//  		return true
1230	//  	default:
1231	//  		return false
1232	//  	}
1233	//  }
1234	_InvalidSelectCase
1235
1236	/* control flow > labels and jumps */
1237
1238	// _UndeclaredLabel occurs when an undeclared label is jumped to.
1239	//
1240	// Example:
1241	//  func f() {
1242	//  	goto L
1243	//  }
1244	_UndeclaredLabel
1245
1246	// _DuplicateLabel occurs when a label is declared more than once.
1247	//
1248	// Example:
1249	//  func f() int {
1250	//  L:
1251	//  L:
1252	//  	return 1
1253	//  }
1254	_DuplicateLabel
1255
1256	// _MisplacedLabel occurs when a break or continue label is not on a for,
1257	// switch, or select statement.
1258	//
1259	// Example:
1260	//  func f() {
1261	//  L:
1262	//  	a := []int{1,2,3}
1263	//  	for _, e := range a {
1264	//  		if e > 10 {
1265	//  			break L
1266	//  		}
1267	//  		println(a)
1268	//  	}
1269	//  }
1270	_MisplacedLabel
1271
1272	// _UnusedLabel occurs when a label is declared but not used.
1273	//
1274	// Example:
1275	//  func f() {
1276	//  L:
1277	//  }
1278	_UnusedLabel
1279
1280	// _JumpOverDecl occurs when a label jumps over a variable declaration.
1281	//
1282	// Example:
1283	//  func f() int {
1284	//  	goto L
1285	//  	x := 2
1286	//  L:
1287	//  	x++
1288	//  	return x
1289	//  }
1290	_JumpOverDecl
1291
1292	// _JumpIntoBlock occurs when a forward jump goes to a label inside a nested
1293	// block.
1294	//
1295	// Example:
1296	//  func f(x int) {
1297	//  	goto L
1298	//  	if x > 0 {
1299	//  	L:
1300	//  		print("inside block")
1301	//  	}
1302	// }
1303	_JumpIntoBlock
1304
1305	/* control flow > calls */
1306
1307	// _InvalidMethodExpr occurs when a pointer method is called but the argument
1308	// is not addressable.
1309	//
1310	// Example:
1311	//  type T struct {}
1312	//
1313	//  func (*T) m() int { return 1 }
1314	//
1315	//  var _ = T.m(T{})
1316	_InvalidMethodExpr
1317
1318	// _WrongArgCount occurs when too few or too many arguments are passed by a
1319	// function call.
1320	//
1321	// Example:
1322	//  func f(i int) {}
1323	//  var x = f()
1324	_WrongArgCount
1325
1326	// _InvalidCall occurs when an expression is called that is not of function
1327	// type.
1328	//
1329	// Example:
1330	//  var x = "x"
1331	//  var y = x()
1332	_InvalidCall
1333
1334	/* control flow > suspended */
1335
1336	// _UnusedResults occurs when a restricted expression-only built-in function
1337	// is suspended via go or defer. Such a suspension discards the results of
1338	// these side-effect free built-in functions, and therefore is ineffectual.
1339	//
1340	// Example:
1341	//  func f(a []int) int {
1342	//  	defer len(a)
1343	//  	return i
1344	//  }
1345	_UnusedResults
1346
1347	// _InvalidDefer occurs when a deferred expression is not a function call,
1348	// for example if the expression is a type conversion.
1349	//
1350	// Example:
1351	//  func f(i int) int {
1352	//  	defer int32(i)
1353	//  	return i
1354	//  }
1355	_InvalidDefer
1356
1357	// _InvalidGo occurs when a go expression is not a function call, for example
1358	// if the expression is a type conversion.
1359	//
1360	// Example:
1361	//  func f(i int) int {
1362	//  	go int32(i)
1363	//  	return i
1364	//  }
1365	_InvalidGo
1366)
1367