Skip to content

Commit 69b0471

Browse files
authored
Merge pull request #16192 from CodaFi/paren-oid-android
[SR-7492][4.2] Project over-parenthesized patterns properly
2 parents 47af334 + 5b8448d commit 69b0471

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,8 +1737,7 @@ namespace {
17371737
//
17381738
// FIXME: SE-0155 makes this case unreachable.
17391739
if (SP->getKind() == PatternKind::Named
1740-
|| SP->getKind() == PatternKind::Any
1741-
|| SP->getKind() == PatternKind::Tuple) {
1740+
|| SP->getKind() == PatternKind::Any) {
17421741
if (auto *TTy = SP->getType()->getAs<TupleType>()) {
17431742
for (auto ty : TTy->getElements()) {
17441743
conArgSpace.push_back(Space::forType(ty.getType(),
@@ -1748,6 +1747,13 @@ namespace {
17481747
conArgSpace.push_back(projectPattern(TC, SP,
17491748
sawDowngradablePattern));
17501749
}
1750+
} else if (SP->getKind() == PatternKind::Tuple) {
1751+
Space argTupleSpace = projectPattern(TC, SP,
1752+
sawDowngradablePattern);
1753+
assert(argTupleSpace.getKind() == SpaceKind::Constructor);
1754+
conArgSpace.insert(conArgSpace.end(),
1755+
argTupleSpace.getSpaces().begin(),
1756+
argTupleSpace.getSpaces().end());
17511757
} else {
17521758
conArgSpace.push_back(projectPattern(TC, SP,
17531759
sawDowngradablePattern));

test/Sema/exhaustive_switch.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ enum Result<T> {
4848
}
4949
}
5050

51+
func overParenthesized() {
52+
// SR-7492: Space projection needs to treat extra paren-patterns explicitly.
53+
let x: Result<(Result<Int>, String)> = .Ok((.Ok(1), "World"))
54+
switch x {
55+
case let .Error(e):
56+
print(e)
57+
case let .Ok((.Error(e), b)):
58+
print(e, b)
59+
case let .Ok((.Ok(a), b)): // No warning here.
60+
print(a, b)
61+
}
62+
}
63+
5164
enum Foo {
5265
case A(Int)
5366
case B(Int)

0 commit comments

Comments
 (0)