Skip to content

Commit 4e08917

Browse files
Allow exchanging tokens when there are also unrelated unexpected tokens
1 parent 40a0bf0 commit 4e08917

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
168168
moveFixIt: (_ misplacedTokens: [TokenSyntax]) -> FixItMessage,
169169
removeRedundantFixIt: (_ misplacedTokens: [TokenSyntax]) -> FixItMessage? = { _ in nil }
170170
) {
171-
guard let incorrectContainer = unexpected,
172-
let misplacedTokens = incorrectContainer.onlyPresentTokens(satisfying: unexpectedTokenCondition)
173-
else {
174-
// If there are no unexpected nodes or the unexpected contain multiple tokens, don't emit a diagnostic.
175-
return
176-
}
171+
guard let incorrectContainer = unexpected else { return }
172+
let misplacedTokens = incorrectContainer.presentTokens(satisfying: unexpectedTokenCondition)
173+
if misplacedTokens.isEmpty { return }
177174

178175
let correctTokens = correctTokens.compactMap({ $0 })
179176

Tests/SwiftParserTest/translated/InitDeinitTests.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,26 @@ final class InitDeinitTests: XCTestCase {
642642
"""
643643
)
644644
}
645-
645+
646+
func testDeinitReasyncThrows() {
647+
assertParse(
648+
"""
649+
class FooClassDeinitializerA {
650+
deinit 1️⃣reasync 2️⃣throws {}
651+
}
652+
""",
653+
diagnostics: [
654+
DiagnosticSpec(locationMarker: "1️⃣", message: "expected async specifier; did you mean 'async'?", fixIts: ["replace 'reasync' with 'async'"]),
655+
DiagnosticSpec(locationMarker: "2️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws'"])
656+
],
657+
fixedSource: """
658+
class FooClassDeinitializerA {
659+
deinit async {}
660+
}
661+
"""
662+
)
663+
}
664+
646665
func testDeinitNameAwait() {
647666
assertParse(
648667
"""
@@ -745,7 +764,6 @@ final class InitDeinitTests: XCTestCase {
745764
}
746765

747766
func testDeinitNameParamsAwaitThrows() {
748-
// TODO: Fix this
749767
assertParse(
750768
"""
751769
class FooClassDeinitializerA {

0 commit comments

Comments
 (0)