]> Cypherpunks repositories - gostls13.git/commitdiff
internal/types/errors: add String method to Code
authorRobert Griesemer <gri@golang.org>
Wed, 15 Mar 2023 20:15:28 +0000 (13:15 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 15 Mar 2023 21:24:23 +0000 (21:24 +0000)
Change-Id: Ia9fb7bdc39c1001c5cbb387d840ed923cf46b9e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/476715
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

src/internal/types/errors/code_string.go [new file with mode: 0644]
src/internal/types/errors/codes.go

diff --git a/src/internal/types/errors/code_string.go b/src/internal/types/errors/code_string.go
new file mode 100644 (file)
index 0000000..303cc3b
--- /dev/null
@@ -0,0 +1,195 @@
+// Code generated by "stringer -type Code codes.go"; DO NOT EDIT.
+
+package errors
+
+import "strconv"
+
+func _() {
+       // An "invalid array index" compiler error signifies that the constant values have changed.
+       // Re-run the stringer command to generate them again.
+       var x [1]struct{}
+       _ = x[InvalidSyntaxTree - -1]
+       _ = x[Test-1]
+       _ = x[BlankPkgName-2]
+       _ = x[MismatchedPkgName-3]
+       _ = x[InvalidPkgUse-4]
+       _ = x[BadImportPath-5]
+       _ = x[BrokenImport-6]
+       _ = x[ImportCRenamed-7]
+       _ = x[UnusedImport-8]
+       _ = x[InvalidInitCycle-9]
+       _ = x[DuplicateDecl-10]
+       _ = x[InvalidDeclCycle-11]
+       _ = x[InvalidTypeCycle-12]
+       _ = x[InvalidConstInit-13]
+       _ = x[InvalidConstVal-14]
+       _ = x[InvalidConstType-15]
+       _ = x[UntypedNilUse-16]
+       _ = x[WrongAssignCount-17]
+       _ = x[UnassignableOperand-18]
+       _ = x[NoNewVar-19]
+       _ = x[MultiValAssignOp-20]
+       _ = x[InvalidIfaceAssign-21]
+       _ = x[InvalidChanAssign-22]
+       _ = x[IncompatibleAssign-23]
+       _ = x[UnaddressableFieldAssign-24]
+       _ = x[NotAType-25]
+       _ = x[InvalidArrayLen-26]
+       _ = x[BlankIfaceMethod-27]
+       _ = x[IncomparableMapKey-28]
+       _ = x[InvalidPtrEmbed-30]
+       _ = x[BadRecv-31]
+       _ = x[InvalidRecv-32]
+       _ = x[DuplicateFieldAndMethod-33]
+       _ = x[DuplicateMethod-34]
+       _ = x[InvalidBlank-35]
+       _ = x[InvalidIota-36]
+       _ = x[MissingInitBody-37]
+       _ = x[InvalidInitSig-38]
+       _ = x[InvalidInitDecl-39]
+       _ = x[InvalidMainDecl-40]
+       _ = x[TooManyValues-41]
+       _ = x[NotAnExpr-42]
+       _ = x[TruncatedFloat-43]
+       _ = x[NumericOverflow-44]
+       _ = x[UndefinedOp-45]
+       _ = x[MismatchedTypes-46]
+       _ = x[DivByZero-47]
+       _ = x[NonNumericIncDec-48]
+       _ = x[UnaddressableOperand-49]
+       _ = x[InvalidIndirection-50]
+       _ = x[NonIndexableOperand-51]
+       _ = x[InvalidIndex-52]
+       _ = x[SwappedSliceIndices-53]
+       _ = x[NonSliceableOperand-54]
+       _ = x[InvalidSliceExpr-55]
+       _ = x[InvalidShiftCount-56]
+       _ = x[InvalidShiftOperand-57]
+       _ = x[InvalidReceive-58]
+       _ = x[InvalidSend-59]
+       _ = x[DuplicateLitKey-60]
+       _ = x[MissingLitKey-61]
+       _ = x[InvalidLitIndex-62]
+       _ = x[OversizeArrayLit-63]
+       _ = x[MixedStructLit-64]
+       _ = x[InvalidStructLit-65]
+       _ = x[MissingLitField-66]
+       _ = x[DuplicateLitField-67]
+       _ = x[UnexportedLitField-68]
+       _ = x[InvalidLitField-69]
+       _ = x[UntypedLit-70]
+       _ = x[InvalidLit-71]
+       _ = x[AmbiguousSelector-72]
+       _ = x[UndeclaredImportedName-73]
+       _ = x[UnexportedName-74]
+       _ = x[UndeclaredName-75]
+       _ = x[MissingFieldOrMethod-76]
+       _ = x[BadDotDotDotSyntax-77]
+       _ = x[NonVariadicDotDotDot-78]
+       _ = x[MisplacedDotDotDot-79]
+       _ = x[InvalidDotDotDot-81]
+       _ = x[UncalledBuiltin-82]
+       _ = x[InvalidAppend-83]
+       _ = x[InvalidCap-84]
+       _ = x[InvalidClose-85]
+       _ = x[InvalidCopy-86]
+       _ = x[InvalidComplex-87]
+       _ = x[InvalidDelete-88]
+       _ = x[InvalidImag-89]
+       _ = x[InvalidLen-90]
+       _ = x[SwappedMakeArgs-91]
+       _ = x[InvalidMake-92]
+       _ = x[InvalidReal-93]
+       _ = x[InvalidAssert-94]
+       _ = x[ImpossibleAssert-95]
+       _ = x[InvalidConversion-96]
+       _ = x[InvalidUntypedConversion-97]
+       _ = x[BadOffsetofSyntax-98]
+       _ = x[InvalidOffsetof-99]
+       _ = x[UnusedExpr-100]
+       _ = x[UnusedVar-101]
+       _ = x[MissingReturn-102]
+       _ = x[WrongResultCount-103]
+       _ = x[OutOfScopeResult-104]
+       _ = x[InvalidCond-105]
+       _ = x[InvalidPostDecl-106]
+       _ = x[InvalidIterVar-108]
+       _ = x[InvalidRangeExpr-109]
+       _ = x[MisplacedBreak-110]
+       _ = x[MisplacedContinue-111]
+       _ = x[MisplacedFallthrough-112]
+       _ = x[DuplicateCase-113]
+       _ = x[DuplicateDefault-114]
+       _ = x[BadTypeKeyword-115]
+       _ = x[InvalidTypeSwitch-116]
+       _ = x[InvalidExprSwitch-117]
+       _ = x[InvalidSelectCase-118]
+       _ = x[UndeclaredLabel-119]
+       _ = x[DuplicateLabel-120]
+       _ = x[MisplacedLabel-121]
+       _ = x[UnusedLabel-122]
+       _ = x[JumpOverDecl-123]
+       _ = x[JumpIntoBlock-124]
+       _ = x[InvalidMethodExpr-125]
+       _ = x[WrongArgCount-126]
+       _ = x[InvalidCall-127]
+       _ = x[UnusedResults-128]
+       _ = x[InvalidDefer-129]
+       _ = x[InvalidGo-130]
+       _ = x[BadDecl-131]
+       _ = x[RepeatedDecl-132]
+       _ = x[InvalidUnsafeAdd-133]
+       _ = x[InvalidUnsafeSlice-134]
+       _ = x[UnsupportedFeature-135]
+       _ = x[NotAGenericType-136]
+       _ = x[WrongTypeArgCount-137]
+       _ = x[CannotInferTypeArgs-138]
+       _ = x[InvalidTypeArg-139]
+       _ = x[InvalidInstanceCycle-140]
+       _ = x[InvalidUnion-141]
+       _ = x[MisplacedConstraintIface-142]
+       _ = x[InvalidMethodTypeParams-143]
+       _ = x[MisplacedTypeParam-144]
+       _ = x[InvalidUnsafeSliceData-145]
+       _ = x[InvalidUnsafeString-146]
+       _ = x[InvalidClear-148]
+}
+
+const (
+       _Code_name_0 = "InvalidSyntaxTree"
+       _Code_name_1 = "TestBlankPkgNameMismatchedPkgNameInvalidPkgUseBadImportPathBrokenImportImportCRenamedUnusedImportInvalidInitCycleDuplicateDeclInvalidDeclCycleInvalidTypeCycleInvalidConstInitInvalidConstValInvalidConstTypeUntypedNilUseWrongAssignCountUnassignableOperandNoNewVarMultiValAssignOpInvalidIfaceAssignInvalidChanAssignIncompatibleAssignUnaddressableFieldAssignNotATypeInvalidArrayLenBlankIfaceMethodIncomparableMapKey"
+       _Code_name_2 = "InvalidPtrEmbedBadRecvInvalidRecvDuplicateFieldAndMethodDuplicateMethodInvalidBlankInvalidIotaMissingInitBodyInvalidInitSigInvalidInitDeclInvalidMainDeclTooManyValuesNotAnExprTruncatedFloatNumericOverflowUndefinedOpMismatchedTypesDivByZeroNonNumericIncDecUnaddressableOperandInvalidIndirectionNonIndexableOperandInvalidIndexSwappedSliceIndicesNonSliceableOperandInvalidSliceExprInvalidShiftCountInvalidShiftOperandInvalidReceiveInvalidSendDuplicateLitKeyMissingLitKeyInvalidLitIndexOversizeArrayLitMixedStructLitInvalidStructLitMissingLitFieldDuplicateLitFieldUnexportedLitFieldInvalidLitFieldUntypedLitInvalidLitAmbiguousSelectorUndeclaredImportedNameUnexportedNameUndeclaredNameMissingFieldOrMethodBadDotDotDotSyntaxNonVariadicDotDotDotMisplacedDotDotDot"
+       _Code_name_3 = "InvalidDotDotDotUncalledBuiltinInvalidAppendInvalidCapInvalidCloseInvalidCopyInvalidComplexInvalidDeleteInvalidImagInvalidLenSwappedMakeArgsInvalidMakeInvalidRealInvalidAssertImpossibleAssertInvalidConversionInvalidUntypedConversionBadOffsetofSyntaxInvalidOffsetofUnusedExprUnusedVarMissingReturnWrongResultCountOutOfScopeResultInvalidCondInvalidPostDecl"
+       _Code_name_4 = "InvalidIterVarInvalidRangeExprMisplacedBreakMisplacedContinueMisplacedFallthroughDuplicateCaseDuplicateDefaultBadTypeKeywordInvalidTypeSwitchInvalidExprSwitchInvalidSelectCaseUndeclaredLabelDuplicateLabelMisplacedLabelUnusedLabelJumpOverDeclJumpIntoBlockInvalidMethodExprWrongArgCountInvalidCallUnusedResultsInvalidDeferInvalidGoBadDeclRepeatedDeclInvalidUnsafeAddInvalidUnsafeSliceUnsupportedFeatureNotAGenericTypeWrongTypeArgCountCannotInferTypeArgsInvalidTypeArgInvalidInstanceCycleInvalidUnionMisplacedConstraintIfaceInvalidMethodTypeParamsMisplacedTypeParamInvalidUnsafeSliceDataInvalidUnsafeString"
+       _Code_name_5 = "InvalidClear"
+)
+
+var (
+       _Code_index_1 = [...]uint16{0, 4, 16, 33, 46, 59, 71, 85, 97, 113, 126, 142, 158, 174, 189, 205, 218, 234, 253, 261, 277, 295, 312, 330, 354, 362, 377, 393, 411}
+       _Code_index_2 = [...]uint16{0, 15, 22, 33, 56, 71, 83, 94, 109, 123, 138, 153, 166, 175, 189, 204, 215, 230, 239, 255, 275, 293, 312, 324, 343, 362, 378, 395, 414, 428, 439, 454, 467, 482, 498, 512, 528, 543, 560, 578, 593, 603, 613, 630, 652, 666, 680, 700, 718, 738, 756}
+       _Code_index_3 = [...]uint16{0, 16, 31, 44, 54, 66, 77, 91, 104, 115, 125, 140, 151, 162, 175, 191, 208, 232, 249, 264, 274, 283, 296, 312, 328, 339, 354}
+       _Code_index_4 = [...]uint16{0, 14, 30, 44, 61, 81, 94, 110, 124, 141, 158, 175, 190, 204, 218, 229, 241, 254, 271, 284, 295, 308, 320, 329, 336, 348, 364, 382, 400, 415, 432, 451, 465, 485, 497, 521, 544, 562, 584, 603}
+)
+
+func (i Code) String() string {
+       switch {
+       case i == -1:
+               return _Code_name_0
+       case 1 <= i && i <= 28:
+               i -= 1
+               return _Code_name_1[_Code_index_1[i]:_Code_index_1[i+1]]
+       case 30 <= i && i <= 79:
+               i -= 30
+               return _Code_name_2[_Code_index_2[i]:_Code_index_2[i+1]]
+       case 81 <= i && i <= 106:
+               i -= 81
+               return _Code_name_3[_Code_index_3[i]:_Code_index_3[i+1]]
+       case 108 <= i && i <= 146:
+               i -= 108
+               return _Code_name_4[_Code_index_4[i]:_Code_index_4[i+1]]
+       case i == 148:
+               return _Code_name_5
+       default:
+               return "Code(" + strconv.FormatInt(int64(i), 10) + ")"
+       }
+}
index 9615f496c80f2bfdeabad279477af20fae612b59..aafc329e728bc15bfeb1b7fa8bf7e4547b7ffffe 100644 (file)
@@ -4,6 +4,8 @@
 
 package errors
 
+//go:generate stringer -type Code codes.go
+
 type Code int
 
 // This file defines the error codes that can be produced during type-checking.