Skip to content

A return followed by default has no expression associated with it #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftCompilerSupport/ConsistencyCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public func _parserConsistencyCheck(
continue
}

print("\(diag.debugDescription)")
print("\(String(cString: filename)): error: \(diag.debugDescription)")
anyDiags = true
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ extension Parser {
let expr: RawExprSyntax?
if
!self.at(any: [
.rightBrace, .caseKeyword, .semicolon, .eof,
.rightBrace, .caseKeyword, .defaultKeyword, .semicolon, .eof,
.poundIfKeyword, .poundErrorKeyword, .poundWarningKeyword,
.poundEndifKeyword, .poundElseKeyword, .poundElseifKeyword
])
Expand Down
9 changes: 8 additions & 1 deletion Tests/SwiftParserTest/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ParserTests: XCTestCase {
}
}

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

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

/// Test all of the files in the "validation-text" directory of the main
/// Swift compiler. This requires the Swift compiler to have been checked
/// out into the "swift" directory alongside swift-syntax.
func testSwiftValidationTestsuite() throws {
try XCTSkipIf(ProcessInfo.processInfo.environment["SKIP_SELF_PARSE"] == "1")
let testDir = URL(fileURLWithPath: #file)
Expand Down Expand Up @@ -139,6 +145,7 @@ public class ParserTests: XCTestCase {
|| fileURL.absoluteString.contains("26101-swift-parser-parsenewdeclattribute.swift")
|| fileURL.absoluteString.contains("26773-swift-diagnosticengine-diagnose.swift")
|| fileURL.absoluteString.contains("parser-cutoff.swift")
|| fileURL.absoluteString.contains("26233-swift-iterabledeclcontext-getmembers.swift")
}
)
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/SwiftParserTest/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ final class StatementTests: XCTestCase {
)

AssertParse("return true ? nil : nil")

AssertParse(
"""
switch command {
case .start:
break

case .stop:
return

default:
break
}
"""
)
}

func testSwitch() {
Expand Down