Skip to content

Remove SyntaxKind conformance to CaseIterable #2292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let syntaxKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! EnumDeclSyntax(
"""
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
public enum SyntaxKind: CaseIterable
public enum SyntaxKind
"""
) {
DeclSyntax("case token")
Expand Down
6 changes: 6 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
- Effect specifiers:
- Description: The `unexpectedAfterThrowsSpecifier` node of the various effect specifiers has been removed.
- Pull request: https://github.com/apple/swift-syntax/pull/2219
- `SyntaxKind` removed conformance to `CaseIterable`
- Description: `SyntaxKind` no longer conforms to `CaseIterable` since there is no good use case to iterate over all syntax kinds.
- Pull request: https://github.com/apple/swift-syntax/pull/2292
- `IntegerLiteralExprSyntax.Radix` removed conformance to `CaseIterable`
- Description: `IntegerLiteralExprSyntax.Radix` no longer conforms to `CaseIterable` since there is no good use case to iterate over all radix kinds.
- Pull request: https://github.com/apple/swift-syntax/pull/2292


## Template
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftRefactor/IntegerLiteralUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SwiftSyntax

extension IntegerLiteralExprSyntax {
public enum Radix: CaseIterable {
public enum Radix {
case binary
case octal
case decimal
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/generated/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

/// Enumerates the known kinds of Syntax represented in the Syntax tree.
public enum SyntaxKind: CaseIterable {
public enum SyntaxKind {
case token
case accessorBlock
case accessorDeclList
Expand Down
11 changes: 9 additions & 2 deletions SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ struct BasicFormat: ParsableCommand, ParseCommand {
var nodeType: String = "SourceFileSyntax"

func run() throws {
let parsableMetatypes = SyntaxKind.allCases.compactMap {
$0.syntaxNodeType as? SyntaxParseable.Type
guard case .choices(let choices) = Syntax.structure else {
fatalError("Expected `Syntax.structure` to be the `choices` case")
}

let parsableMetatypes = choices.compactMap { (choice) -> SyntaxParseable.Type? in
guard case .node(let nodeType) = choice else {
return nil
}
return nodeType as? SyntaxParseable.Type
}
let parsableMetatypesByName = Dictionary(
parsableMetatypes.map {
Expand Down