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