Skip to content

Commit 8f36550

Browse files
authored
Merge pull request #842 from DougGregor/return-before-default
A return followed by default has no expression associated with it
2 parents 5cc4cdc + dc27c21 commit 8f36550

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

Sources/SwiftCompilerSupport/ConsistencyCheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public func _parserConsistencyCheck(
7373
continue
7474
}
7575

76-
print("\(diag.debugDescription)")
76+
print("\(String(cString: filename)): error: \(diag.debugDescription)")
7777
anyDiags = true
7878
}
7979

Sources/SwiftParser/Statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ extension Parser {
865865
let expr: RawExprSyntax?
866866
if
867867
!self.at(any: [
868-
.rightBrace, .caseKeyword, .semicolon, .eof,
868+
.rightBrace, .caseKeyword, .defaultKeyword, .semicolon, .eof,
869869
.poundIfKeyword, .poundErrorKeyword, .poundWarningKeyword,
870870
.poundEndifKeyword, .poundElseKeyword, .poundElseifKeyword
871871
])

Tests/SwiftParserTest/ParserTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ParserTests: XCTestCase {
3333
}
3434
}
3535

36-
/// Run parsr tests on all of the Swift files in the
36+
/// Run parsr tests on all of the Swift files in the given path, recursively.
3737
func runParserTests(
3838
name: String, path: URL, checkDiagnostics: Bool,
3939
shouldExclude: (URL) -> Bool = { _ in false }
@@ -76,6 +76,9 @@ public class ParserTests: XCTestCase {
7676
)
7777
}
7878

79+
/// Test all of the files in the "test" directory of the main Swift compiler.
80+
/// This requires the Swift compiler to have been checked out into the "swift"
81+
/// directory alongside swift-syntax.
7982
func testSwiftTestsuite() throws {
8083
try XCTSkipIf(ProcessInfo.processInfo.environment["SKIP_SELF_PARSE"] == "1")
8184
let testDir = URL(fileURLWithPath: #file)
@@ -97,6 +100,9 @@ public class ParserTests: XCTestCase {
97100
)
98101
}
99102

103+
/// Test all of the files in the "validation-text" directory of the main
104+
/// Swift compiler. This requires the Swift compiler to have been checked
105+
/// out into the "swift" directory alongside swift-syntax.
100106
func testSwiftValidationTestsuite() throws {
101107
try XCTSkipIf(ProcessInfo.processInfo.environment["SKIP_SELF_PARSE"] == "1")
102108
let testDir = URL(fileURLWithPath: #file)
@@ -139,6 +145,7 @@ public class ParserTests: XCTestCase {
139145
|| fileURL.absoluteString.contains("26101-swift-parser-parsenewdeclattribute.swift")
140146
|| fileURL.absoluteString.contains("26773-swift-diagnosticengine-diagnose.swift")
141147
|| fileURL.absoluteString.contains("parser-cutoff.swift")
148+
|| fileURL.absoluteString.contains("26233-swift-iterabledeclcontext-getmembers.swift")
142149
}
143150
)
144151
}

Tests/SwiftParserTest/Statements.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ final class StatementTests: XCTestCase {
110110
)
111111

112112
AssertParse("return true ? nil : nil")
113+
114+
AssertParse(
115+
"""
116+
switch command {
117+
case .start:
118+
break
119+
120+
case .stop:
121+
return
122+
123+
default:
124+
break
125+
}
126+
"""
127+
)
113128
}
114129

115130
func testSwitch() {

0 commit comments

Comments
 (0)