Skip to content

Commit effa261

Browse files
committed
[CSSimplify] Move invalid pack expansion check to enable closure result conversion
Checking for pack expansion type mismatch impedes non-Void-to-Void conversion allowed for single-expression closures. Resolves: rdar://108904190
1 parent 406b7a6 commit effa261

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7282,22 +7282,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
72827282
}
72837283
}
72847284

7285-
// Matching types where one side is a pack expansion and the other is not
7286-
// means a pack expansion was used where it isn't supported.
7287-
if (type1->is<PackExpansionType>() != type2->is<PackExpansionType>()) {
7288-
if (!shouldAttemptFixes())
7289-
return getTypeMatchFailure(locator);
7290-
7291-
if (type1->isPlaceholder() || type2->isPlaceholder())
7292-
return getTypeMatchSuccess();
7293-
7294-
auto *loc = getConstraintLocator(locator);
7295-
if (recordFix(AllowInvalidPackExpansion::create(*this, loc)))
7296-
return getTypeMatchFailure(locator);
7297-
7298-
return getTypeMatchSuccess();
7299-
}
7300-
73017285
if (kind >= ConstraintKind::Conversion) {
73027286
// An lvalue of type T1 can be converted to a value of type T2 so long as
73037287
// T1 is convertible to T2 (by loading the value). Note that we cannot get
@@ -7720,6 +7704,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
77207704
}
77217705
}
77227706

7707+
// Matching types where one side is a pack expansion and the other is not
7708+
// means a pack expansion was used where it isn't supported.
7709+
if (type1->is<PackExpansionType>() != type2->is<PackExpansionType>()) {
7710+
if (!shouldAttemptFixes())
7711+
return getTypeMatchFailure(locator);
7712+
7713+
if (type1->isPlaceholder() || type2->isPlaceholder())
7714+
return getTypeMatchSuccess();
7715+
7716+
auto *loc = getConstraintLocator(locator);
7717+
if (recordFix(AllowInvalidPackExpansion::create(*this, loc)))
7718+
return getTypeMatchFailure(locator);
7719+
7720+
return getTypeMatchSuccess();
7721+
}
7722+
77237723
// Attempt fixes iff it's allowed, both types are concrete and
77247724
// we are not in the middle of attempting one already.
77257725
if (shouldAttemptFixes() && !flags.contains(TMF_ApplyingFix)) {

test/Constraints/pack-expansion-expressions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,8 @@ do {
495495
_ = (repeat overloaded(42, each v)) // Ok
496496
}
497497
}
498+
499+
// rdar://108904190 - top-level 'repeat' not allowed in single-expression closures
500+
func test_pack_expansion_to_void_conv_for_closure_result<each T>(x: repeat each T) -> () -> () {
501+
return { repeat print(each x) } // Ok
502+
}

0 commit comments

Comments
 (0)