Skip to content

Commit cc68375

Browse files
committed
Adapt to Tuple-In-OptionalSome Patterns in Space Projection
The space engine goes out of its way to rewrite OptionalSome patterns using the postfix-? sugar into .some(...). Unfortunately, it performed the following remapping: (x, y, z, ...)? -> .some(x, y, z, ...) This syntactic form used to behave correctly. However, we are no longer flattening nested tuples so the correct rewrite is: (x, y, z, ...)? -> .some((x, y, z)) Correct this space projection rule. rdar://62200966
1 parent 14ff43e commit cc68375

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,6 @@ namespace {
212212
}
213213
return Space(T, H, SP);
214214
}
215-
static Space forConstructor(Type T, DeclName H,
216-
std::forward_list<Space> SP) {
217-
// No need to filter SP here; this is only used to copy other
218-
// Constructor spaces.
219-
return Space(T, H, SP);
220-
}
221215
static Space forBool(bool C) {
222216
return Space(C);
223217
}
@@ -1441,7 +1435,7 @@ namespace {
14411435
if (subSpace.getKind() == SpaceKind::Constructor &&
14421436
subSpace.getHead().getBaseIdentifier().empty()) {
14431437
return Space::forConstructor(item->getType(), name,
1444-
std::move(subSpace.getSpaces()));
1438+
{subSpace});
14451439
}
14461440
return Space::forConstructor(item->getType(), name, subSpace);
14471441
}

test/Sema/exhaustive_switch.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,3 +1438,15 @@ enum SR11212Tests {
14381438
}
14391439

14401440
} // end SR11212Tests
1441+
1442+
func sr12412() {
1443+
enum E {
1444+
case x
1445+
case y
1446+
}
1447+
switch (E.x, true) as Optional<(e: E, b: Bool)> {
1448+
case nil, (e: .x, b: _)?: break
1449+
case (e: .y, b: false)?: break
1450+
case (e: .y, b: true)?: break
1451+
}
1452+
}

0 commit comments

Comments
 (0)