Skip to content

Commit 50e70fb

Browse files
committed
[CSGen] Preserve labels during splat situations in pattern matching context
Tuple splat/implosion is (still) allowed for patterns (with a warning in Swift 5) so we need to use `SingleApply` while looking up members to make sure that e.g. `case test(x: Int, y: Int)` gets the labels preserved when matched with `case let .test(tuple)` and `Compound` when associated values form a tuple pattern.
1 parent 72221c9 commit 50e70fb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,19 @@ namespace {
24052405
Type memberType = CS.createTypeVariable(
24062406
CS.getConstraintLocator(locator),
24072407
TVO_CanBindToLValue | TVO_CanBindToNoEscape);
2408-
FunctionRefKind functionRefKind = FunctionRefKind::Compound;
2408+
2409+
// Tuple splat is still allowed for patterns (with a warning in Swift 5)
2410+
// so we need to start here from single-apply to make sure that e.g.
2411+
// `case test(x: Int, y: Int)` gets the labels preserved when matched
2412+
// with `case let .test(tuple)`.
2413+
FunctionRefKind functionRefKind = FunctionRefKind::SingleApply;
2414+
// If sub-pattern is a tuple we'd need to mark reference as compound,
2415+
// that would make sure that the labels are dropped in cases
2416+
// when `case` has a single tuple argument (tuple explosion) or multiple
2417+
// arguments (tuple-to-tuple conversion).
2418+
if (dyn_cast_or_null<TuplePattern>(enumPattern->getSubPattern()))
2419+
functionRefKind = FunctionRefKind::Compound;
2420+
24092421
if (enumPattern->getParentType() || enumPattern->getParentTypeRepr()) {
24102422
// Resolve the parent type.
24112423
const auto parentType = [&] {

0 commit comments

Comments
 (0)