From b3f36929bece076466569b8d0b99b73b27f4e052 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 9 Aug 2023 12:32:19 -0700 Subject: [PATCH] Ensure there are no optional syntax collection in the syntax tree All syntax collections should be non-optional, which makes it easier to work with them. Also, the semantics of what an empty collection vs. a `nil` collection have not been clear. --- .../SyntaxSupport/AvailabilityNodes.swift | 3 +- .../Sources/SyntaxSupport/ExprNodes.swift | 3 +- .../Sources/SyntaxSupport/StmtNodes.swift | 6 ++-- .../ValidateSyntaxNodes.swift | 19 +++++++++++ Sources/SwiftParser/Availability.swift | 2 +- Sources/SwiftParser/Expressions.swift | 2 +- Sources/SwiftParser/Statements.swift | 4 +-- .../ParseDiagnosticsGenerator.swift | 8 ++--- .../generated/raw/RawSyntaxNodes.swift | 32 +++++++++---------- .../generated/raw/RawSyntaxValidation.swift | 8 ++--- .../generated/syntaxNodes/SyntaxNodes.swift | 30 ++++++++--------- .../syntaxNodes/SyntaxStmtNodes.swift | 10 +++--- .../generated/BuildableNodes.swift | 6 ++-- Tests/SwiftParserTest/AvailabilityTests.swift | 3 +- 14 files changed, 75 insertions(+), 61 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift index bf76105feb9..7ded692bb3d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift @@ -180,8 +180,7 @@ public let AVAILABILITY_NODES: [Node] = [ Child( name: "Components", kind: .collection(kind: .versionComponentList, collectionElementName: "VersionComponent"), - documentation: "Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`", - isOptional: true + documentation: "Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`" ), ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift index 3dbef50c38a..f0aa43c8807 100644 --- a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift @@ -354,8 +354,7 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "Items", - kind: .collection(kind: .closureCaptureList, collectionElementName: "Item"), - isOptional: true + kind: .collection(kind: .closureCaptureList, collectionElementName: "Item") ), Child( name: "RightSquare", diff --git a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift index 927b06f43ba..0b704c4f7f3 100644 --- a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift @@ -86,8 +86,7 @@ public let STMT_NODES: [Node] = [ ), Child( name: "CatchItems", - kind: .collection(kind: .catchItemList, collectionElementName: "CatchItem"), - isOptional: true + kind: .collection(kind: .catchItemList, collectionElementName: "CatchItem", defaultsToEmpty: true) ), Child( name: "Body", @@ -240,8 +239,7 @@ public let STMT_NODES: [Node] = [ ), Child( name: "CatchClauses", - kind: .collection(kind: .catchClauseList, collectionElementName: "CatchClause"), - isOptional: true + kind: .collection(kind: .catchClauseList, collectionElementName: "CatchClause", defaultsToEmpty: true) ), ] ), diff --git a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift index 9852ce51fb9..bac83f2773c 100644 --- a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift +++ b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift @@ -760,4 +760,23 @@ class ValidateSyntaxNodes: XCTestCase { assertFailuresMatchXFails(failures, expectedFailures: []) } + + func testNoOptionalSyntaxCollections() { + var failures: [ValidationFailure] = [] + + for node in SYNTAX_NODES.compactMap(\.layoutNode) { + for child in node.children { + if case .collection = child.kind, child.isOptional, !child.isUnexpectedNodes { + failures.append( + ValidationFailure( + node: node.kind, + message: "child '\(child.name)' is an optional syntax collection. All syntax collections should be non-optional." + ) + ) + } + } + } + + assertFailuresMatchXFails(failures, expectedFailures: []) + } } diff --git a/Sources/SwiftParser/Availability.swift b/Sources/SwiftParser/Availability.swift index 8101741d60a..e4e51822078 100644 --- a/Sources/SwiftParser/Availability.swift +++ b/Sources/SwiftParser/Availability.swift @@ -299,7 +299,7 @@ extension Parser { let unexpectedAfterComponents = self.parseUnexpectedVersionTokens() return RawVersionTupleSyntax( major: major, - components: nil, + components: RawVersionComponentListSyntax(elements: [], arena: self.arena), unexpectedAfterComponents, arena: self.arena ) diff --git a/Sources/SwiftParser/Expressions.swift b/Sources/SwiftParser/Expressions.swift index 837deea55df..6e8b60bd2e1 100644 --- a/Sources/SwiftParser/Expressions.swift +++ b/Sources/SwiftParser/Expressions.swift @@ -1733,7 +1733,7 @@ extension Parser { captures = RawClosureCaptureClauseSyntax( leftSquare: lsquare, - items: elements.isEmpty ? nil : RawClosureCaptureListSyntax(elements: elements, arena: self.arena), + items: RawClosureCaptureListSyntax(elements: elements, arena: self.arena), RawUnexpectedNodesSyntax(unexpectedNodes, arena: self.arena), rightSquare: rsquare, arena: self.arena diff --git a/Sources/SwiftParser/Statements.swift b/Sources/SwiftParser/Statements.swift index 3675e9d71f4..02d2a387bb1 100644 --- a/Sources/SwiftParser/Statements.swift +++ b/Sources/SwiftParser/Statements.swift @@ -384,7 +384,7 @@ extension Parser { unexpectedBeforeDoKeyword, doKeyword: doKeyword, body: body, - catchClauses: elements.isEmpty ? nil : RawCatchClauseListSyntax(elements: elements, arena: self.arena), + catchClauses: RawCatchClauseListSyntax(elements: elements, arena: self.arena), arena: self.arena ) } @@ -416,7 +416,7 @@ extension Parser { return RawCatchClauseSyntax( unexpectedBeforeCatchKeyword, catchKeyword: catchKeyword, - catchItems: catchItems.isEmpty ? nil : RawCatchItemListSyntax(elements: catchItems, arena: self.arena), + catchItems: RawCatchItemListSyntax(elements: catchItems, arena: self.arena), body: body, arena: self.arena ) diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index bb3f106fdbb..7873a381019 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -1936,19 +1936,17 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { } if let unexpectedAfterComponents = node.unexpectedAfterComponents { - if let components = node.components, - unexpectedAfterComponents.allSatisfy({ $0.is(VersionComponentSyntax.self) }) - { + if unexpectedAfterComponents.allSatisfy({ $0.is(VersionComponentSyntax.self) }) { addDiagnostic( unexpectedAfterComponents, - TrailingVersionAreIgnored(major: node.major, components: components), + TrailingVersionAreIgnored(major: node.major, components: node.components), handledNodes: [unexpectedAfterComponents.id] ) } else { addDiagnostic( unexpectedAfterComponents, CannotParseVersionTuple(versionTuple: unexpectedAfterComponents), - handledNodes: [node.major.id, node.components?.id, unexpectedAfterComponents.id].compactMap { $0 } + handledNodes: [node.major.id, node.components.id, unexpectedAfterComponents.id] ) } } diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift index 05b376e6a4f..669bce3a2a0 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift @@ -2715,7 +2715,7 @@ public struct RawCatchClauseSyntax: RawSyntaxNodeProtocol { _ unexpectedBeforeCatchKeyword: RawUnexpectedNodesSyntax? = nil, catchKeyword: RawTokenSyntax, _ unexpectedBetweenCatchKeywordAndCatchItems: RawUnexpectedNodesSyntax? = nil, - catchItems: RawCatchItemListSyntax?, + catchItems: RawCatchItemListSyntax, _ unexpectedBetweenCatchItemsAndBody: RawUnexpectedNodesSyntax? = nil, body: RawCodeBlockSyntax, _ unexpectedAfterBody: RawUnexpectedNodesSyntax? = nil, @@ -2727,7 +2727,7 @@ public struct RawCatchClauseSyntax: RawSyntaxNodeProtocol { layout[0] = unexpectedBeforeCatchKeyword?.raw layout[1] = catchKeyword.raw layout[2] = unexpectedBetweenCatchKeywordAndCatchItems?.raw - layout[3] = catchItems?.raw + layout[3] = catchItems.raw layout[4] = unexpectedBetweenCatchItemsAndBody?.raw layout[5] = body.raw layout[6] = unexpectedAfterBody?.raw @@ -2747,8 +2747,8 @@ public struct RawCatchClauseSyntax: RawSyntaxNodeProtocol { layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var catchItems: RawCatchItemListSyntax? { - layoutView.children[3].map(RawCatchItemListSyntax.init(raw:)) + public var catchItems: RawCatchItemListSyntax { + layoutView.children[3].map(RawCatchItemListSyntax.init(raw:))! } public var unexpectedBetweenCatchItemsAndBody: RawUnexpectedNodesSyntax? { @@ -3129,7 +3129,7 @@ public struct RawClosureCaptureClauseSyntax: RawSyntaxNodeProtocol { _ unexpectedBeforeLeftSquare: RawUnexpectedNodesSyntax? = nil, leftSquare: RawTokenSyntax, _ unexpectedBetweenLeftSquareAndItems: RawUnexpectedNodesSyntax? = nil, - items: RawClosureCaptureListSyntax?, + items: RawClosureCaptureListSyntax, _ unexpectedBetweenItemsAndRightSquare: RawUnexpectedNodesSyntax? = nil, rightSquare: RawTokenSyntax, _ unexpectedAfterRightSquare: RawUnexpectedNodesSyntax? = nil, @@ -3141,7 +3141,7 @@ public struct RawClosureCaptureClauseSyntax: RawSyntaxNodeProtocol { layout[0] = unexpectedBeforeLeftSquare?.raw layout[1] = leftSquare.raw layout[2] = unexpectedBetweenLeftSquareAndItems?.raw - layout[3] = items?.raw + layout[3] = items.raw layout[4] = unexpectedBetweenItemsAndRightSquare?.raw layout[5] = rightSquare.raw layout[6] = unexpectedAfterRightSquare?.raw @@ -3161,8 +3161,8 @@ public struct RawClosureCaptureClauseSyntax: RawSyntaxNodeProtocol { layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var items: RawClosureCaptureListSyntax? { - layoutView.children[3].map(RawClosureCaptureListSyntax.init(raw:)) + public var items: RawClosureCaptureListSyntax { + layoutView.children[3].map(RawClosureCaptureListSyntax.init(raw:))! } public var unexpectedBetweenItemsAndRightSquare: RawUnexpectedNodesSyntax? { @@ -7067,7 +7067,7 @@ public struct RawDoStmtSyntax: RawStmtSyntaxNodeProtocol { _ unexpectedBetweenDoKeywordAndBody: RawUnexpectedNodesSyntax? = nil, body: RawCodeBlockSyntax, _ unexpectedBetweenBodyAndCatchClauses: RawUnexpectedNodesSyntax? = nil, - catchClauses: RawCatchClauseListSyntax?, + catchClauses: RawCatchClauseListSyntax, _ unexpectedAfterCatchClauses: RawUnexpectedNodesSyntax? = nil, arena: __shared SyntaxArena ) { @@ -7079,7 +7079,7 @@ public struct RawDoStmtSyntax: RawStmtSyntaxNodeProtocol { layout[2] = unexpectedBetweenDoKeywordAndBody?.raw layout[3] = body.raw layout[4] = unexpectedBetweenBodyAndCatchClauses?.raw - layout[5] = catchClauses?.raw + layout[5] = catchClauses.raw layout[6] = unexpectedAfterCatchClauses?.raw } self.init(unchecked: raw) @@ -7105,8 +7105,8 @@ public struct RawDoStmtSyntax: RawStmtSyntaxNodeProtocol { layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var catchClauses: RawCatchClauseListSyntax? { - layoutView.children[5].map(RawCatchClauseListSyntax.init(raw:)) + public var catchClauses: RawCatchClauseListSyntax { + layoutView.children[5].map(RawCatchClauseListSyntax.init(raw:))! } public var unexpectedAfterCatchClauses: RawUnexpectedNodesSyntax? { @@ -22129,7 +22129,7 @@ public struct RawVersionTupleSyntax: RawSyntaxNodeProtocol { _ unexpectedBeforeMajor: RawUnexpectedNodesSyntax? = nil, major: RawTokenSyntax, _ unexpectedBetweenMajorAndComponents: RawUnexpectedNodesSyntax? = nil, - components: RawVersionComponentListSyntax?, + components: RawVersionComponentListSyntax, _ unexpectedAfterComponents: RawUnexpectedNodesSyntax? = nil, arena: __shared SyntaxArena ) { @@ -22139,7 +22139,7 @@ public struct RawVersionTupleSyntax: RawSyntaxNodeProtocol { layout[0] = unexpectedBeforeMajor?.raw layout[1] = major.raw layout[2] = unexpectedBetweenMajorAndComponents?.raw - layout[3] = components?.raw + layout[3] = components.raw layout[4] = unexpectedAfterComponents?.raw } self.init(unchecked: raw) @@ -22157,8 +22157,8 @@ public struct RawVersionTupleSyntax: RawSyntaxNodeProtocol { layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var components: RawVersionComponentListSyntax? { - layoutView.children[3].map(RawVersionComponentListSyntax.init(raw:)) + public var components: RawVersionComponentListSyntax { + layoutView.children[3].map(RawVersionComponentListSyntax.init(raw:))! } public var unexpectedAfterComponents: RawUnexpectedNodesSyntax? { diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index facef27463f..a4db9ca3c77 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -501,7 +501,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("catch")])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 3, verify(layout[3], as: RawCatchItemListSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawCatchItemListSyntax.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 5, verify(layout[5], as: RawCodeBlockSyntax.self)) assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) @@ -547,7 +547,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.leftSquare)])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 3, verify(layout[3], as: RawClosureCaptureListSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawClosureCaptureListSyntax.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 5, verify(layout[5], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.rightSquare)])) assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) @@ -994,7 +994,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawCodeBlockSyntax.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 5, verify(layout[5], as: RawCatchClauseListSyntax?.self)) + assertNoError(kind, 5, verify(layout[5], as: RawCatchClauseListSyntax.self)) assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) case .documentationAttributeArgumentList: for (index, element) in layout.enumerated() { @@ -2638,7 +2638,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.integerLiteral)])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 3, verify(layout[3], as: RawVersionComponentListSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawVersionComponentListSyntax.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) case .whereClause: assert(layout.count == 5) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift index 96406384f52..c73927a9401 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift @@ -1925,7 +1925,7 @@ public struct CatchClauseSyntax: SyntaxProtocol, SyntaxHashable { _ unexpectedBeforeCatchKeyword: UnexpectedNodesSyntax? = nil, catchKeyword: TokenSyntax = .keyword(.catch), _ unexpectedBetweenCatchKeywordAndCatchItems: UnexpectedNodesSyntax? = nil, - catchItems: CatchItemListSyntax? = nil, + catchItems: CatchItemListSyntax = [], _ unexpectedBetweenCatchItemsAndBody: UnexpectedNodesSyntax? = nil, body: CodeBlockSyntax, _ unexpectedAfterBody: UnexpectedNodesSyntax? = nil, @@ -1947,7 +1947,7 @@ public struct CatchClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBeforeCatchKeyword?.raw, catchKeyword.raw, unexpectedBetweenCatchKeywordAndCatchItems?.raw, - catchItems?.raw, + catchItems.raw, unexpectedBetweenCatchItemsAndBody?.raw, body.raw, unexpectedAfterBody?.raw @@ -1992,12 +1992,12 @@ public struct CatchClauseSyntax: SyntaxProtocol, SyntaxHashable { } } - public var catchItems: CatchItemListSyntax? { + public var catchItems: CatchItemListSyntax { get { - return data.child(at: 3, parent: Syntax(self)).map(CatchItemListSyntax.init) + return CatchItemListSyntax(data.child(at: 3, parent: Syntax(self))!) } set(value) { - self = CatchClauseSyntax(data.replacingChild(at: 3, with: value?.data, arena: SyntaxArena())) + self = CatchClauseSyntax(data.replacingChild(at: 3, with: value.data, arena: SyntaxArena())) } } @@ -2259,7 +2259,7 @@ public struct ClosureCaptureClauseSyntax: SyntaxProtocol, SyntaxHashable { _ unexpectedBeforeLeftSquare: UnexpectedNodesSyntax? = nil, leftSquare: TokenSyntax = .leftSquareToken(), _ unexpectedBetweenLeftSquareAndItems: UnexpectedNodesSyntax? = nil, - items: ClosureCaptureListSyntax? = nil, + items: ClosureCaptureListSyntax, _ unexpectedBetweenItemsAndRightSquare: UnexpectedNodesSyntax? = nil, rightSquare: TokenSyntax = .rightSquareToken(), _ unexpectedAfterRightSquare: UnexpectedNodesSyntax? = nil, @@ -2281,7 +2281,7 @@ public struct ClosureCaptureClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBeforeLeftSquare?.raw, leftSquare.raw, unexpectedBetweenLeftSquareAndItems?.raw, - items?.raw, + items.raw, unexpectedBetweenItemsAndRightSquare?.raw, rightSquare.raw, unexpectedAfterRightSquare?.raw @@ -2326,12 +2326,12 @@ public struct ClosureCaptureClauseSyntax: SyntaxProtocol, SyntaxHashable { } } - public var items: ClosureCaptureListSyntax? { + public var items: ClosureCaptureListSyntax { get { - return data.child(at: 3, parent: Syntax(self)).map(ClosureCaptureListSyntax.init) + return ClosureCaptureListSyntax(data.child(at: 3, parent: Syntax(self))!) } set(value) { - self = ClosureCaptureClauseSyntax(data.replacingChild(at: 3, with: value?.data, arena: SyntaxArena())) + self = ClosureCaptureClauseSyntax(data.replacingChild(at: 3, with: value.data, arena: SyntaxArena())) } } @@ -19002,7 +19002,7 @@ public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable { _ unexpectedBeforeMajor: UnexpectedNodesSyntax? = nil, major: TokenSyntax, _ unexpectedBetweenMajorAndComponents: UnexpectedNodesSyntax? = nil, - components: VersionComponentListSyntax? = nil, + components: VersionComponentListSyntax, _ unexpectedAfterComponents: UnexpectedNodesSyntax? = nil, trailingTrivia: Trivia? = nil @@ -19020,7 +19020,7 @@ public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBeforeMajor?.raw, major.raw, unexpectedBetweenMajorAndComponents?.raw, - components?.raw, + components.raw, unexpectedAfterComponents?.raw ] let raw = RawSyntax.makeLayout( @@ -19065,12 +19065,12 @@ public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable { } /// Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0` - public var components: VersionComponentListSyntax? { + public var components: VersionComponentListSyntax { get { - return data.child(at: 3, parent: Syntax(self)).map(VersionComponentListSyntax.init) + return VersionComponentListSyntax(data.child(at: 3, parent: Syntax(self))!) } set(value) { - self = VersionTupleSyntax(data.replacingChild(at: 3, with: value?.data, arena: SyntaxArena())) + self = VersionTupleSyntax(data.replacingChild(at: 3, with: value.data, arena: SyntaxArena())) } } diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift index 48729900771..642c7bb8c79 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift @@ -540,7 +540,7 @@ public struct DoStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { _ unexpectedBetweenDoKeywordAndBody: UnexpectedNodesSyntax? = nil, body: CodeBlockSyntax, _ unexpectedBetweenBodyAndCatchClauses: UnexpectedNodesSyntax? = nil, - catchClauses: CatchClauseListSyntax? = nil, + catchClauses: CatchClauseListSyntax = [], _ unexpectedAfterCatchClauses: UnexpectedNodesSyntax? = nil, trailingTrivia: Trivia? = nil @@ -562,7 +562,7 @@ public struct DoStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenDoKeywordAndBody?.raw, body.raw, unexpectedBetweenBodyAndCatchClauses?.raw, - catchClauses?.raw, + catchClauses.raw, unexpectedAfterCatchClauses?.raw ] let raw = RawSyntax.makeLayout( @@ -623,12 +623,12 @@ public struct DoStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { } } - public var catchClauses: CatchClauseListSyntax? { + public var catchClauses: CatchClauseListSyntax { get { - return data.child(at: 5, parent: Syntax(self)).map(CatchClauseListSyntax.init) + return CatchClauseListSyntax(data.child(at: 5, parent: Syntax(self))!) } set(value) { - self = DoStmtSyntax(data.replacingChild(at: 5, with: value?.data, arena: SyntaxArena())) + self = DoStmtSyntax(data.replacingChild(at: 5, with: value.data, arena: SyntaxArena())) } } diff --git a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift index 2cffa152a8d..2064d31c349 100644 --- a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift +++ b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift @@ -136,7 +136,7 @@ extension CatchClauseSyntax { unexpectedBeforeCatchKeyword: UnexpectedNodesSyntax? = nil, catchKeyword: TokenSyntax = .keyword(.catch), unexpectedBetweenCatchKeywordAndCatchItems: UnexpectedNodesSyntax? = nil, - catchItems: CatchItemListSyntax? = nil, + catchItems: CatchItemListSyntax = [], unexpectedBetweenCatchItemsAndBody: UnexpectedNodesSyntax? = nil, unexpectedAfterBody: UnexpectedNodesSyntax? = nil, @CodeBlockItemListBuilder bodyBuilder: () throws -> CodeBlockItemListSyntax, @@ -213,7 +213,7 @@ extension ClosureCaptureClauseSyntax { unexpectedBetweenItemsAndRightSquare: UnexpectedNodesSyntax? = nil, rightSquare: TokenSyntax = .rightSquareToken(), unexpectedAfterRightSquare: UnexpectedNodesSyntax? = nil, - @ClosureCaptureListBuilder itemsBuilder: () throws -> ClosureCaptureListSyntax?, + @ClosureCaptureListBuilder itemsBuilder: () throws -> ClosureCaptureListSyntax, trailingTrivia: Trivia? = nil ) rethrows { try self.init( @@ -356,7 +356,7 @@ extension DoStmtSyntax { doKeyword: TokenSyntax = .keyword(.do), unexpectedBetweenDoKeywordAndBody: UnexpectedNodesSyntax? = nil, unexpectedBetweenBodyAndCatchClauses: UnexpectedNodesSyntax? = nil, - catchClauses: CatchClauseListSyntax? = nil, + catchClauses: CatchClauseListSyntax = [], unexpectedAfterCatchClauses: UnexpectedNodesSyntax? = nil, @CodeBlockItemListBuilder bodyBuilder: () throws -> CodeBlockItemListSyntax, trailingTrivia: Trivia? = nil diff --git a/Tests/SwiftParserTest/AvailabilityTests.swift b/Tests/SwiftParserTest/AvailabilityTests.swift index 642df4317f0..9e5e1883256 100644 --- a/Tests/SwiftParserTest/AvailabilityTests.swift +++ b/Tests/SwiftParserTest/AvailabilityTests.swift @@ -107,7 +107,8 @@ final class AvailabilityTests: XCTestCase { func test() {} """, substructure: VersionTupleSyntax( - major: .integerLiteral("10") + major: .integerLiteral("10"), + components: [] ) )