Skip to content

Commit 94968a7

Browse files
committed
# This is a combination of 8 commits.
# This is the 1st commit message: fixed testAvailabilityQuery34 and testAvailabilityQueryUnavailability28 # This is the commit message swiftlang#2: Update Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift Co-authored-by: Kim de Vos <[email protected]> # This is the commit message swiftlang#3: added fixedSource in test case # This is the commit message swiftlang#4: minor changes # This is the commit message swiftlang#5: implemented recovery inside the parser # This is the commit message swiftlang#6: runned format.py # This is the commit message swiftlang#7: minor changes # This is the commit message swiftlang#8: minor changes
1 parent 68056e8 commit 94968a7

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

Sources/SwiftParser/Availability.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ extension Parser {
218218
(unexpectedBeforePlatform, platform) = self.expect(.identifier)
219219
}
220220

221+
let unexpectedComparison: RawUnexpectedNodesSyntax?
222+
if let greaterThanOrEqualTo = self.consumeIfContextualPunctuator(">=") {
223+
unexpectedComparison = RawUnexpectedNodesSyntax([greaterThanOrEqualTo], arena: self.arena)
224+
} else {
225+
unexpectedComparison = nil
226+
}
227+
221228
let version: RawVersionTupleSyntax?
222229
if self.at(.integerLiteral, .floatingLiteral) {
223230
version = self.parseVersionTuple()
@@ -228,6 +235,7 @@ extension Parser {
228235
return RawAvailabilityVersionRestrictionSyntax(
229236
unexpectedBeforePlatform,
230237
platform: platform,
238+
unexpectedComparison,
231239
version: version,
232240
arena: self.arena
233241
)

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,25 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
440440
return .visitChildren
441441
}
442442

443+
public override func visit(_ node: AvailabilityVersionRestrictionSyntax) -> SyntaxVisitorContinueKind {
444+
if shouldSkip(node) {
445+
return .skipChildren
446+
}
447+
if let unexpected = node.unexpectedBetweenPlatformAndVersion,
448+
unexpected.onlyToken(where: { $0.tokenKind == .binaryOperator(">=") }) != nil
449+
{
450+
addDiagnostic(
451+
unexpected,
452+
.versionComparisonNotNeeded,
453+
fixIts: [
454+
FixIt(message: RemoveNodesFixIt(unexpected), changes: .makeMissing(unexpected))
455+
],
456+
handledNodes: [unexpected.id]
457+
)
458+
}
459+
return .visitChildren
460+
}
461+
443462
public override func visit(_ node: ConditionElementSyntax) -> SyntaxVisitorContinueKind {
444463
if shouldSkip(node) {
445464
return .skipChildren

Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ extension DiagnosticMessage where Self == StaticParserError {
212212
public static var unexpectedSemicolon: Self {
213213
.init("unexpected ';' separator")
214214
}
215+
public static var versionComparisonNotNeeded: Self {
216+
.init("version comparison not needed")
217+
}
215218
}
216219

217220
// MARK: - Diagnostics (please sort alphabetically)

Tests/SwiftParserTest/translated/AvailabilityQueryTests.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,12 @@ final class AvailabilityQueryTests: XCTestCase {
407407
}
408408
""",
409409
diagnostics: [
410-
// TODO: (good first issue) Old parser expected error on line 1: version comparison not needed, Fix-It replacements: 19 - 22 = ''
411-
DiagnosticSpec(message: "unexpected code '>= 10.51, *' in availability condition")
412-
]
410+
DiagnosticSpec(message: "version comparison not needed", fixIts: ["remove '>='"])
411+
],
412+
fixedSource: """
413+
if #available(OSX 10.51, *) {
414+
}
415+
"""
413416
)
414417
}
415418

Tests/SwiftParserTest/translated/AvailabilityQueryUnavailabilityTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ final class AvailabilityQueryUnavailabilityTests: XCTestCase {
365365
}
366366
""",
367367
diagnostics: [
368-
// TODO: (good first issue) Old parser expected error on line 2: version comparison not needed, Fix-It replacements: 21 - 24 = ''
369-
DiagnosticSpec(message: "unexpected code '>= 10.51' in availability condition")
368+
DiagnosticSpec(message: "version comparison not needed", fixIts: ["remove '>='"])
370369
]
371370
)
372371
}

0 commit comments

Comments
 (0)