Skip to content

Commit 4f8b9fb

Browse files
committed
Parse an Optional Code Block in Deinits
The body of a deinitializer is not strictly required a la declarations in swiftinterface file.
1 parent fceb672 commit 4f8b9fb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ extension Parser {
10341034
@_spi(RawSyntax)
10351035
public mutating func parseDeinitializerDeclaration(_ attrs: DeclAttributes) -> RawDeinitializerDeclSyntax {
10361036
let deinitKeyword = self.eat(.deinitKeyword)
1037-
let items = self.parseCodeBlock()
1037+
let items = self.parseOptionalCodeBlock()
10381038
return RawDeinitializerDeclSyntax(
10391039
attributes: attrs.attributes, modifiers: attrs.modifiers,
10401040
deinitKeyword: deinitKeyword, body: items,

Tests/SwiftParserTest/Declarations.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ final class DeclarationTests: XCTestCase {
708708
]
709709
)
710710
}
711+
712+
func testDeinitializers() {
713+
AssertParse("deinit {}", { $0.parseDeinitializerDeclaration(.empty) })
714+
AssertParse("deinit", { $0.parseDeinitializerDeclaration(.empty) })
715+
}
711716
}
712717

713718
extension Parser.DeclAttributes {

0 commit comments

Comments
 (0)