@@ -1641,12 +1641,12 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
16411641 return getTypeMatchFailure (locator);
16421642
16431643 // 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.
16451646
16461647 // Conformance to 'Any' always holds.
16471648 if (type2->isAny ()) {
1648- auto *fnTy = type1->getAs <FunctionType>();
1649- if (!fnTy || !fnTy->isNoEscape ())
1649+ if (!type1->isNoEscape ())
16501650 return getTypeMatchSuccess ();
16511651
16521652 if (shouldAttemptFixes ()) {
@@ -1835,21 +1835,19 @@ ConstraintSystem::matchTypesBindTypeVar(
18351835 return getTypeMatchFailure (locator);
18361836 }
18371837
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))
18511846 return getTypeMatchFailure (locator);
1852- }
1847+
1848+ // Allow no-escape function to be bound with recorded fix.
1849+ } else {
1850+ return getTypeMatchFailure (locator);
18531851 }
18541852 }
18551853
@@ -2413,23 +2411,21 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
24132411 type2->isExistentialType ()) {
24142412
24152413 // Penalize conversions to Any, and disallow conversions of
2416- // noescape functions to Any.
2414+ // types containing noescape functions to Any.
24172415 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))
24312422 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);
24332429 }
24342430 }
24352431
0 commit comments