@@ -1641,12 +1641,12 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
1641
1641
return getTypeMatchFailure (locator);
1642
1642
1643
1643
// FIXME; Feels like a hack...nothing actually "conforms" here, and
1644
- // we need to disallow conversions from @noescape functions to Any.
1644
+ // we need to disallow conversions from types containing @noescape
1645
+ // functions to Any.
1645
1646
1646
1647
// Conformance to 'Any' always holds.
1647
1648
if (type2->isAny ()) {
1648
- auto *fnTy = type1->getAs <FunctionType>();
1649
- if (!fnTy || !fnTy->isNoEscape ())
1649
+ if (!type1->isNoEscape ())
1650
1650
return getTypeMatchSuccess ();
1651
1651
1652
1652
if (shouldAttemptFixes ()) {
@@ -1835,21 +1835,19 @@ ConstraintSystem::matchTypesBindTypeVar(
1835
1835
return getTypeMatchFailure (locator);
1836
1836
}
1837
1837
1838
- // Disallow bindings of noescape functions to type variables that
1839
- // represent an opened archetype. If we allowed this it would allow
1840
- // the noescape function to potentially escape.
1841
- if (auto *fnTy = type->getAs <FunctionType>()) {
1842
- if (fnTy->isNoEscape () && typeVar->getImpl ().getGenericParameter ()) {
1843
- if (shouldAttemptFixes ()) {
1844
- auto *fix = MarkExplicitlyEscaping::create (
1845
- *this , getConstraintLocator (locator));
1846
- if (recordFix (fix))
1847
- return getTypeMatchFailure (locator);
1848
-
1849
- // Allow no-escape function to be bound with recorded fix.
1850
- } else {
1838
+ // Disallow bindings of types containing noescape functions to type
1839
+ // variables that represent an opened generic parameter. If we allowed
1840
+ // this it would allow noescape functions to potentially escape.
1841
+ if (type->isNoEscape () && typeVar->getImpl ().getGenericParameter ()) {
1842
+ if (shouldAttemptFixes ()) {
1843
+ auto *fix = MarkExplicitlyEscaping::create (
1844
+ *this , getConstraintLocator (locator));
1845
+ if (recordFix (fix))
1851
1846
return getTypeMatchFailure (locator);
1852
- }
1847
+
1848
+ // Allow no-escape function to be bound with recorded fix.
1849
+ } else {
1850
+ return getTypeMatchFailure (locator);
1853
1851
}
1854
1852
}
1855
1853
@@ -2413,23 +2411,21 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2413
2411
type2->isExistentialType ()) {
2414
2412
2415
2413
// Penalize conversions to Any, and disallow conversions of
2416
- // noescape functions to Any.
2414
+ // types containing noescape functions to Any.
2417
2415
if (kind >= ConstraintKind::Conversion && type2->isAny ()) {
2418
- if (auto *fnTy = type1->getAs <FunctionType>()) {
2419
- if (fnTy->isNoEscape ()) {
2420
- if (shouldAttemptFixes ()) {
2421
- auto &ctx = getASTContext ();
2422
- auto *fix = MarkExplicitlyEscaping::create (
2423
- *this , getConstraintLocator (locator), ctx.TheAnyType );
2424
- if (recordFix (fix))
2425
- return getTypeMatchFailure (locator);
2426
-
2427
- // Allow 'no-escape' functions to be converted to 'Any'
2428
- // with a recorded fix that helps us to properly diagnose
2429
- // such situations.
2430
- } else {
2416
+ if (type1->isNoEscape ()) {
2417
+ if (shouldAttemptFixes ()) {
2418
+ auto &ctx = getASTContext ();
2419
+ auto *fix = MarkExplicitlyEscaping::create (
2420
+ *this , getConstraintLocator (locator), ctx.TheAnyType );
2421
+ if (recordFix (fix))
2431
2422
return getTypeMatchFailure (locator);
2432
- }
2423
+
2424
+ // Allow 'no-escape' functions to be converted to 'Any'
2425
+ // with a recorded fix that helps us to properly diagnose
2426
+ // such situations.
2427
+ } else {
2428
+ return getTypeMatchFailure (locator);
2433
2429
}
2434
2430
}
2435
2431
0 commit comments