@@ -7039,6 +7039,14 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
7039
7039
return formUnsolvedResult();
7040
7040
}
7041
7041
7042
+ // Closure result is allowed to convert to Void in certain circumstances,
7043
+ // let's forego tuple matching because it is guaranteed to fail and jump
7044
+ // to `() -> T` to `() -> Void` rule.
7045
+ if (locator.endsWith<LocatorPathElt::ClosureBody>()) {
7046
+ if (containsPackExpansionType(tuple1) && tuple2->isVoid())
7047
+ break;
7048
+ }
7049
+
7042
7050
// Add each tuple type to the locator before matching the element types.
7043
7051
// This is useful for diagnostics, because the error message can use the
7044
7052
// full tuple type for several element mismatches. Use the original types
@@ -7336,22 +7344,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
7336
7344
}
7337
7345
}
7338
7346
7339
- // Matching types where one side is a pack expansion and the other is not
7340
- // means a pack expansion was used where it isn't supported.
7341
- if (type1->is<PackExpansionType>() != type2->is<PackExpansionType>()) {
7342
- if (!shouldAttemptFixes())
7343
- return getTypeMatchFailure(locator);
7344
-
7345
- if (type1->isPlaceholder() || type2->isPlaceholder())
7346
- return getTypeMatchSuccess();
7347
-
7348
- auto *loc = getConstraintLocator(locator);
7349
- if (recordFix(AllowInvalidPackExpansion::create(*this, loc)))
7350
- return getTypeMatchFailure(locator);
7351
-
7352
- return getTypeMatchSuccess();
7353
- }
7354
-
7355
7347
if (kind >= ConstraintKind::Conversion) {
7356
7348
// An lvalue of type T1 can be converted to a value of type T2 so long as
7357
7349
// T1 is convertible to T2 (by loading the value). Note that we cannot get
@@ -7774,6 +7766,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
7774
7766
}
7775
7767
}
7776
7768
7769
+ // Matching types where one side is a pack expansion and the other is not
7770
+ // means a pack expansion was used where it isn't supported.
7771
+ if (type1->is<PackExpansionType>() != type2->is<PackExpansionType>()) {
7772
+ if (!shouldAttemptFixes())
7773
+ return getTypeMatchFailure(locator);
7774
+
7775
+ if (type1->isPlaceholder() || type2->isPlaceholder())
7776
+ return getTypeMatchSuccess();
7777
+
7778
+ auto *loc = getConstraintLocator(locator);
7779
+ if (recordFix(AllowInvalidPackExpansion::create(*this, loc)))
7780
+ return getTypeMatchFailure(locator);
7781
+
7782
+ return getTypeMatchSuccess();
7783
+ }
7784
+
7777
7785
// Attempt fixes iff it's allowed, both types are concrete and
7778
7786
// we are not in the middle of attempting one already.
7779
7787
if (shouldAttemptFixes() && !flags.contains(TMF_ApplyingFix)) {
0 commit comments