@@ -6865,10 +6865,18 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6865
6865
isInDefaultArgumentContext = (initalizerCtx->getInitializerKind () ==
6866
6866
InitializerKind::DefaultArgument);
6867
6867
auto toEI = toFunc->getExtInfo ();
6868
+
6869
+ auto fromFunc = fromType->getAs <FunctionType>();
6870
+
6868
6871
// Coercion to an autoclosure type produces an implicit closure.
6872
+ // The constraint solver only performs this conversion when the source
6873
+ // type is not an autoclosure function type. That's a weird rule in
6874
+ // some rules, but it's easy to follow here. Really we just shouldn't
6875
+ // represent autoclosures as a bit on function types.
6869
6876
// FIXME: The type checker is more lenient, and allows @autoclosures to
6870
6877
// be subtypes of non-@autoclosures, which is bogus.
6871
- if (toFunc->isAutoClosure ()) {
6878
+ if (toFunc->isAutoClosure () &&
6879
+ (!fromFunc || !fromFunc->isAutoClosure ())) {
6872
6880
// The function type without @noescape if we are in the default argument
6873
6881
// context.
6874
6882
auto newToFuncType = toFunc;
@@ -6909,7 +6917,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6909
6917
6910
6918
// Coercion from one function type to another, this produces a
6911
6919
// FunctionConversionExpr in its full generality.
6912
- if (auto fromFunc = fromType-> getAs <FunctionType>() ) {
6920
+ if (fromFunc) {
6913
6921
// If we have a ClosureExpr, then we can safely propagate the 'no escape'
6914
6922
// bit to the closure without invalidating prior analysis.
6915
6923
auto fromEI = fromFunc->getExtInfo ();
0 commit comments