From d78f8aa7bd92e0d36a04551cedff94262d095a53 Mon Sep 17 00:00:00 2001 From: Padmashree06 Date: Sat, 17 Jan 2026 03:37:12 +0530 Subject: [PATCH 1/3] Add diagnostics to testRecovery28 --- Sources/SwiftParser/Statements.swift | 8 +++++++- .../SwiftParserTest/translated/RecoveryTests.swift | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftParser/Statements.swift b/Sources/SwiftParser/Statements.swift index 53ee258ce81..0be235772a0 100644 --- a/Sources/SwiftParser/Statements.swift +++ b/Sources/SwiftParser/Statements.swift @@ -534,7 +534,13 @@ extension Parser { let (unexpectedBeforeRepeatKeyword, repeatKeyword) = self.eat(repeatHandle) let body = self.parseCodeBlock(introducer: repeatKeyword) let (unexpectedBeforeWhileKeyword, whileKeyword) = self.expect(.keyword(.while)) - let condition = self.parseExpression(flavor: .basic, pattern: .none) + let condition : RawExprSyntax + if self.at(.leftBrace){ + condition = RawExprSyntax(RawMissingExprSyntax(arena: self.arena)) + } + else{ + condition = self.parseExpression(flavor: .basic, pattern: .none) + } return RawRepeatStmtSyntax( unexpectedBeforeRepeatKeyword, repeatKeyword: repeatKeyword, diff --git a/Tests/SwiftParserTest/translated/RecoveryTests.swift b/Tests/SwiftParserTest/translated/RecoveryTests.swift index 4bb52f7411c..7d8bb073421 100644 --- a/Tests/SwiftParserTest/translated/RecoveryTests.swift +++ b/Tests/SwiftParserTest/translated/RecoveryTests.swift @@ -438,12 +438,24 @@ final class RecoveryTests: ParserTestCase { assertParse( """ repeat { - } while { true }() + } while1️⃣{ true }2️⃣() """, diagnostics: [ // TODO: Old parser expected error on line 2: missing condition in 'while' statement // TODO: Old parser expected error on line 2: consecutive statements on a line must be separated by ';', Fix-It replacements: 10 - 10 = ';' // TODO: Old parser expected warning on line 2: result of call to closure returning 'Bool' is unused + DiagnosticSpec( + locationMarker:"1️⃣" , + message: "missing condition in 'while' statement" + ), + DiagnosticSpec( + locationMarker: "2️⃣", + message: "consecutive statements on a line must be separated by ';'", + fixIts: ["seperate statements with ';"] + ), + DiagnosticSpec( + message: "result of call to closure returning 'Bool' is unused" + ) ] ) } From 7538e4ddd52b5cfc5f7a84565fc32c34d56e6b86 Mon Sep 17 00:00:00 2001 From: Padmashree06 Date: Sat, 17 Jan 2026 04:08:28 +0530 Subject: [PATCH 2/3] Align recovery test diagnostics with current parser behavior --- Sources/SwiftParser/Statements.swift | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Sources/SwiftParser/Statements.swift b/Sources/SwiftParser/Statements.swift index 0be235772a0..53ee258ce81 100644 --- a/Sources/SwiftParser/Statements.swift +++ b/Sources/SwiftParser/Statements.swift @@ -534,13 +534,7 @@ extension Parser { let (unexpectedBeforeRepeatKeyword, repeatKeyword) = self.eat(repeatHandle) let body = self.parseCodeBlock(introducer: repeatKeyword) let (unexpectedBeforeWhileKeyword, whileKeyword) = self.expect(.keyword(.while)) - let condition : RawExprSyntax - if self.at(.leftBrace){ - condition = RawExprSyntax(RawMissingExprSyntax(arena: self.arena)) - } - else{ - condition = self.parseExpression(flavor: .basic, pattern: .none) - } + let condition = self.parseExpression(flavor: .basic, pattern: .none) return RawRepeatStmtSyntax( unexpectedBeforeRepeatKeyword, repeatKeyword: repeatKeyword, From 9933acb7530c847d01731a034732fccf934d6113 Mon Sep 17 00:00:00 2001 From: Padmashree06 Date: Tue, 20 Jan 2026 21:33:37 +0530 Subject: [PATCH 3/3] Format code using swift-format --- Tests/SwiftParserTest/translated/RecoveryTests.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/SwiftParserTest/translated/RecoveryTests.swift b/Tests/SwiftParserTest/translated/RecoveryTests.swift index 7d8bb073421..b0ef42cabeb 100644 --- a/Tests/SwiftParserTest/translated/RecoveryTests.swift +++ b/Tests/SwiftParserTest/translated/RecoveryTests.swift @@ -445,17 +445,17 @@ final class RecoveryTests: ParserTestCase { // TODO: Old parser expected error on line 2: consecutive statements on a line must be separated by ';', Fix-It replacements: 10 - 10 = ';' // TODO: Old parser expected warning on line 2: result of call to closure returning 'Bool' is unused DiagnosticSpec( - locationMarker:"1️⃣" , + locationMarker: "1️⃣", message: "missing condition in 'while' statement" - ), + ), DiagnosticSpec( - locationMarker: "2️⃣", + locationMarker: "2️⃣", message: "consecutive statements on a line must be separated by ';'", fixIts: ["seperate statements with ';"] - ), + ), DiagnosticSpec( message: "result of call to closure returning 'Bool' is unused" - ) + ), ] ) }