Skip to content

Commit 106183a

Browse files
authored
Merge pull request #2292 from ahoppen/ahoppen/case-iterable
Remove `SyntaxKind` conformance to `CaseIterable`
2 parents e8659bb + aa33736 commit 106183a

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let syntaxKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
1919
try! EnumDeclSyntax(
2020
"""
2121
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
22-
public enum SyntaxKind: CaseIterable
22+
public enum SyntaxKind
2323
"""
2424
) {
2525
DeclSyntax("case token")

Release Notes/511.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
- Effect specifiers:
1717
- Description: The `unexpectedAfterThrowsSpecifier` node of the various effect specifiers has been removed.
1818
- Pull request: https://github.com/apple/swift-syntax/pull/2219
19+
- `SyntaxKind` removed conformance to `CaseIterable`
20+
- Description: `SyntaxKind` no longer conforms to `CaseIterable` since there is no good use case to iterate over all syntax kinds.
21+
- Pull request: https://github.com/apple/swift-syntax/pull/2292
22+
- `IntegerLiteralExprSyntax.Radix` removed conformance to `CaseIterable`
23+
- Description: `IntegerLiteralExprSyntax.Radix` no longer conforms to `CaseIterable` since there is no good use case to iterate over all radix kinds.
24+
- Pull request: https://github.com/apple/swift-syntax/pull/2292
1925

2026

2127
## Template

Sources/SwiftRefactor/IntegerLiteralUtilities.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SwiftSyntax
1414

1515
extension IntegerLiteralExprSyntax {
16-
public enum Radix: CaseIterable {
16+
public enum Radix {
1717
case binary
1818
case octal
1919
case decimal

Sources/SwiftSyntax/generated/SyntaxKind.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
16-
public enum SyntaxKind: CaseIterable {
16+
public enum SyntaxKind {
1717
case token
1818
case accessorBlock
1919
case accessorDeclList

SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ struct BasicFormat: ParsableCommand, ParseCommand {
4747
var nodeType: String = "SourceFileSyntax"
4848

4949
func run() throws {
50-
let parsableMetatypes = SyntaxKind.allCases.compactMap {
51-
$0.syntaxNodeType as? SyntaxParseable.Type
50+
guard case .choices(let choices) = Syntax.structure else {
51+
fatalError("Expected `Syntax.structure` to be the `choices` case")
52+
}
53+
54+
let parsableMetatypes = choices.compactMap { (choice) -> SyntaxParseable.Type? in
55+
guard case .node(let nodeType) = choice else {
56+
return nil
57+
}
58+
return nodeType as? SyntaxParseable.Type
5259
}
5360
let parsableMetatypesByName = Dictionary(
5461
parsableMetatypes.map {

0 commit comments

Comments
 (0)