Skip to content

Commit e2cc07e

Browse files
committed
Slightly simplify detection of diagnostics
1 parent 6311794 commit e2cc07e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Sources/SwiftParser/Diagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
9696
if shouldSkip(node) {
9797
return .skipChildren
9898
}
99+
// Detect C-style for loops based on two semicolons which could not be parsed between the 'for' keyword and the '{'
99100
// This is mostly a proof-of-concept implementation to produce more complex diagnostics.
100-
if let unexpectedCondition = node.body.unexpectedBeforeLeftBrace {
101-
// Detect C-style for loops based on two semicolons which could not be parsed between the 'for' keyword and the '{'
102-
if unexpectedCondition.tokens(withKind: .semicolon).count == 2 {
103-
addDiagnostic(node, .cStyleForLoop)
104-
markNodesAsHandled(node.inKeyword.id, unexpectedCondition.id)
105-
}
101+
if let unexpectedCondition = node.body.unexpectedBeforeLeftBrace,
102+
unexpectedCondition.tokens(withKind: .semicolon).count == 2 {
103+
addDiagnostic(node, .cStyleForLoop)
104+
markNodesAsHandled(node.inKeyword.id, unexpectedCondition.id)
106105
}
107106
return .visitChildren
108107
}
@@ -111,12 +110,12 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
111110
if shouldSkip(node) {
112111
return .skipChildren
113112
}
114-
if let output = node.output, let unexpectedBeforeReturnType = output.unexpectedBetweenArrowAndReturnType {
115-
if let throwsInReturnPosition = unexpectedBeforeReturnType.tokens(withKind: .throwsKeyword).first {
113+
if let output = node.output,
114+
let unexpectedBeforeReturnType = output.unexpectedBetweenArrowAndReturnType,
115+
let throwsInReturnPosition = unexpectedBeforeReturnType.tokens(withKind: .throwsKeyword).first {
116116
addDiagnostic(throwsInReturnPosition, .throwsInReturnPosition)
117117
markNodesAsHandled(unexpectedBeforeReturnType.id, throwsInReturnPosition.id)
118118
return .visitChildren
119-
}
120119
}
121120
return .visitChildren
122121
}

0 commit comments

Comments
 (0)