Skip to content

Commit cd0ce57

Browse files
authored
Merge pull request #731 from tshortli/unknown-default
Resolve `switch covers known cases, but 'Enum' may have additional unknown values` warnings
2 parents cc309e6 + cb653e7 commit cd0ce57

File tree

8 files changed

+99
-0
lines changed

8 files changed

+99
-0
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ fileprivate extension Compiler.ByteCodeGen {
156156
name, isScalarMode: options.semanticLevel == .unicodeScalar)
157157
case .relative:
158158
throw Unsupported("Backreference kind: \(ref)")
159+
#if RESILIENT_LIBRARIES
160+
@unknown default:
161+
fatalError()
162+
#endif
159163
}
160164
}
161165

@@ -683,6 +687,10 @@ fileprivate extension Compiler.ByteCodeGen {
683687
// quantification break if trying to restore to a prior
684688
// iteration because the register got overwritten?
685689
//
690+
#if RESILIENT_LIBRARIES
691+
@unknown default:
692+
fatalError()
693+
#endif
686694
}
687695

688696
builder.label(exit)

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ extension AST.Atom {
324324
.backtrackingDirective, .changeMatchingOptions, .invalid:
325325
// FIXME: implement
326326
return nil
327+
328+
#if RESILIENT_LIBRARIES
329+
@unknown default:
330+
fatalError()
331+
#endif
327332
}
328333
}
329334
}
@@ -685,7 +690,13 @@ extension AST.Atom.CharacterProperty {
685690

686691
case .invalid:
687692
throw Unreachable("Expected valid property")
693+
694+
#if RESILIENT_LIBRARIES
695+
@unknown default:
696+
throw Unreachable("Unknown kind \(kind)")
697+
#endif
688698
}
699+
689700
}()
690701

691702
if !isInverted { return preInversion }
@@ -855,6 +866,10 @@ extension Unicode.BinaryProperty {
855866
case .expandsOnNFC, .expandsOnNFD, .expandsOnNFKD,
856867
.expandsOnNFKC:
857868
throw Unsupported("Unicode-deprecated: \(self)")
869+
#if RESILIENT_LIBRARIES
870+
@unknown default:
871+
break
872+
#endif
858873
}
859874

860875
throw Unsupported("TODO: map prop \(self)")
@@ -905,6 +920,10 @@ extension Unicode.POSIXProperty {
905920
case .xdigit:
906921
return consume(propertyScalarPredicate(\.isHexDigit)) // or number
907922

923+
#if RESILIENT_LIBRARIES
924+
@unknown default:
925+
fatalError()
926+
#endif
908927
}
909928
}
910929
}
@@ -1023,6 +1042,11 @@ extension Unicode.ExtendedGeneralCategory {
10231042
return consume(categoryScalarPredicate(.paragraphSeparator))
10241043
case .spaceSeparator:
10251044
return consume(categoryScalarPredicate(.spaceSeparator))
1045+
1046+
#if RESILIENT_LIBRARIES
1047+
@unknown default:
1048+
fatalError()
1049+
#endif
10261050
}
10271051
}
10281052
}

Sources/_StringProcessing/Engine/InstPayload.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ struct QuantifyPayload: RawRepresentable {
431431
kindVal = 1
432432
case .possessive:
433433
kindVal = 2
434+
#if RESILIENT_LIBRARIES
435+
@unknown default:
436+
fatalError()
437+
#endif
434438
}
435439
// TODO: refactor / reimplement
436440
let maxExtraTripsVal: UInt64 = maxExtraTrips == nil ? 1 : UInt64(maxExtraTrips!) << 1

Sources/_StringProcessing/LiteralPrinter.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ extension LiteralPrinter {
216216
output("{,\(n.value!)}")
217217
case let .range(low, high):
218218
output("{\(low.value!),\(high.value!)}")
219+
#if RESILIENT_LIBRARIES
220+
@unknown default:
221+
fatalError()
222+
#endif
219223
}
220224

221225
outputQuantificationKind(kind)
@@ -235,6 +239,10 @@ extension LiteralPrinter {
235239
output(options.isReluctantByDefault ? "" : "?")
236240
case .possessive:
237241
output("+")
242+
#if RESILIENT_LIBRARIES
243+
@unknown default:
244+
fatalError()
245+
#endif
238246
}
239247
case let .syntax(kind):
240248
// Syntactically-specified quantification modifiers can stay as-is.
@@ -245,6 +253,10 @@ extension LiteralPrinter {
245253
output("?")
246254
case .possessive:
247255
output("+")
256+
#if RESILIENT_LIBRARIES
257+
@unknown default:
258+
fatalError()
259+
#endif
248260
}
249261
}
250262
}
@@ -351,6 +363,10 @@ extension LiteralPrinter {
351363
output("\\g{\(prefix)\(abs(value))}")
352364
case .named(let name):
353365
output("\\g{\(name)}")
366+
#if RESILIENT_LIBRARIES
367+
@unknown default:
368+
fatalError()
369+
#endif
354370
}
355371
}
356372

@@ -558,6 +574,11 @@ extension AST.MatchingOption.Kind {
558574

559575
// NSRE Compatibility option; no literal representation
560576
case .nsreCompatibleDot: return nil
577+
578+
#if RESILIENT_LIBRARIES
579+
@unknown default:
580+
fatalError()
581+
#endif
561582
}
562583
}
563584
}
@@ -597,6 +618,11 @@ extension DSLTree._AST.GroupKind {
597618

598619
case let .changeMatchingOptions(sequence):
599620
return sequence._patternString + ":"
621+
622+
#if RESILIENT_LIBRARIES
623+
@unknown default:
624+
fatalError()
625+
#endif
600626
}
601627
}
602628
}

Sources/_StringProcessing/MatchingOptions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ extension MatchingOptions {
217217
self = .extended
218218
case .extraExtended:
219219
self = .extraExtended
220+
#if RESILIENT_LIBRARIES
221+
@unknown default:
222+
fatalError()
223+
#endif
220224
}
221225
}
222226

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,11 @@ extension AST.Atom {
11051105

11061106
case .changeMatchingOptions:
11071107
return "/* TODO: change matching options */"
1108+
1109+
#if RESILIENT_LIBRARIES
1110+
@unknown default:
1111+
fatalError()
1112+
#endif
11081113
}
11091114
}
11101115
}
@@ -1125,6 +1130,9 @@ extension AST.Quantification.Amount {
11251130
case let .nOrMore(n): return "Repeat(\(n._patternBase)...)"
11261131
case let .upToN(n): return "Repeat(...\(n._patternBase))"
11271132
case let .range(n, m): return "Repeat(\(n._patternBase)...\(m._patternBase))"
1133+
#if RESILIENT_LIBRARIES
1134+
@unknown default: fatalError()
1135+
#endif
11281136
}
11291137
}
11301138

@@ -1144,6 +1152,9 @@ extension AST.Quantification.Kind {
11441152
case .eager: return ".eager"
11451153
case .reluctant: return ".reluctant"
11461154
case .possessive: return ".possessive"
1155+
#if RESILIENT_LIBRARIES
1156+
@unknown default: fatalError()
1157+
#endif
11471158
}
11481159
}
11491160
}

Sources/_StringProcessing/Regex/ASTConversion.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ extension AST.Node {
9797
case let .absentFunction(abs):
9898
// TODO: What should this map to?
9999
return .absentFunction(.init(ast: abs))
100+
101+
#if RESILIENT_LIBRARIES
102+
@unknown default:
103+
fatalError()
104+
#endif
100105
}
101106
}
102107

@@ -141,9 +146,18 @@ extension AST.CustomCharacterClass {
141146
return .intersection(lhs, rhs)
142147
case .symmetricDifference:
143148
return .symmetricDifference(lhs, rhs)
149+
#if RESILIENT_LIBRARIES
150+
@unknown default:
151+
fatalError()
152+
#endif
144153
}
145154
case let .trivia(t):
146155
return .trivia(t.contents)
156+
157+
#if RESILIENT_LIBRARIES
158+
@unknown default:
159+
fatalError()
160+
#endif
147161
}
148162
}
149163

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ extension CaptureList.Builder {
651651
addCaptures(of: child, optionalNesting: nesting, visibleInTypedOutput: visibleInTypedOutput)
652652
case .clearer, .repeater, .stopper:
653653
break
654+
#if RESILIENT_LIBRARIES
655+
@unknown default:
656+
fatalError()
657+
#endif
654658
}
655659

656660
case let .convertedRegexLiteral(n, _):
@@ -926,6 +930,10 @@ extension DSLTree {
926930
return true
927931
case .exactly(let num), .nOrMore(let num), .range(let num, _):
928932
return num.value.map { $0 > 0 } ?? false
933+
#if RESILIENT_LIBRARIES
934+
@unknown default:
935+
fatalError()
936+
#endif
929937
}
930938
}
931939
}

0 commit comments

Comments
 (0)