Skip to content

Commit 283c4cc

Browse files
authored
Merge pull request #936 from ahoppen/ahoppen/review-comments
Address review comments
2 parents fa1d089 + 2034441 commit 283c4cc

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Sources/SwiftParser/Diagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
464464
return .skipChildren
465465
}
466466
if node.expression.is(MissingExprSyntax.self) {
467-
addDiagnostic(node.expression, .expectedExpressionAfterTry, handledNodes: [node.expression.id])
467+
addDiagnostic(node.expression, .expectedExpressionAfterTry, fixIts: [
468+
FixIt(message: InsertTokenFixIt(missingNodes: [Syntax(node.expression)]), changes: [
469+
.makePresent(node: node.expression)
470+
])
471+
], handledNodes: [node.expression.id])
468472
}
469473
return .visitChildren
470474
}

Sources/SwiftSyntax/Syntax.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ public extension SyntaxProtocol {
225225
return nil
226226
}
227227
let siblings = NonNilRawSyntaxChildren(parent, viewMode: viewMode)
228+
// `self` could be a missing node at index 0 and `viewMode` be `.sourceAccurate`.
229+
// In that case `siblings` skips over the missing `self` node and has a `startIndex > 0`.
228230
if self.index >= siblings.startIndex {
229231
for absoluteRaw in siblings[..<self.index].reversed() {
230232
let child = Syntax(SyntaxData(absoluteRaw, parent: parent))

Tests/SwiftParserTest/translated/TryTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ final class TryTests: XCTestCase {
266266
""",
267267
diagnostics: [
268268
DiagnosticSpec(locationMarker: "1️⃣", message: "'try' must be placed on the thrown expression", fixIts: ["move 'try' after 'throw'"]),
269-
DiagnosticSpec(locationMarker: "2️⃣", message: "expected expression after 'try'"),
270-
], fixedSource: "throw try"
269+
DiagnosticSpec(locationMarker: "2️⃣", message: "expected expression after 'try'", fixIts: ["insert expression"]),
270+
], fixedSource: "throw try <#expression#>"
271271
)
272272
}
273273

0 commit comments

Comments
 (0)