@@ -854,6 +854,10 @@ namespace {
854
854
->getForwardingSubstitutions (M);
855
855
entityType = GFT->substGenericArgs (subs);
856
856
} else {
857
+ if (auto objType =
858
+ entityType->getImplicitlyUnwrappedOptionalObjectType ())
859
+ entityType = objType;
860
+
857
861
entityType = DC->mapTypeIntoContext (entityType);
858
862
}
859
863
}
@@ -5620,7 +5624,14 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5620
5624
callExpr->setFn (operatorRef);
5621
5625
};
5622
5626
5623
- auto fnType = fnExpr->getType ()->getRValueType ();
5627
+ auto getFuncType = [](Type type) -> Type {
5628
+ auto fnType = type->getRValueType ();
5629
+ if (auto objectType = fnType->getImplicitlyUnwrappedOptionalObjectType ())
5630
+ return objectType;
5631
+ return fnType;
5632
+ };
5633
+
5634
+ auto fnType = getFuncType (fnExpr->getType ());
5624
5635
5625
5636
// If we have a contextual type, and if we have an ambiguously typed function
5626
5637
// result from our previous check, we re-type-check it using this contextual
@@ -5631,9 +5642,8 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5631
5642
// produce better diagnostics below by diagnosing this here rather than trying
5632
5643
// to peel apart the failed conversion to function type.
5633
5644
if (CS->getContextualType () &&
5634
- (isUnresolvedOrTypeVarType (fnExpr->getType ()) ||
5635
- (fnExpr->getType ()->is <AnyFunctionType>() &&
5636
- fnExpr->getType ()->hasUnresolvedType ()))) {
5645
+ (isUnresolvedOrTypeVarType (fnType) ||
5646
+ (fnType->is <AnyFunctionType>() && fnType->hasUnresolvedType ()))) {
5637
5647
// FIXME: Prevent typeCheckChildIndependently from transforming expressions,
5638
5648
// because if we try to typecheck OSR expression with contextual type,
5639
5649
// it'll end up converting it into DeclRefExpr based on contextual info,
@@ -5650,15 +5660,15 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5650
5660
&listener);
5651
5661
5652
5662
if (type.hasValue ())
5653
- fnType = type.getValue ()-> getRValueType ( );
5663
+ fnType = getFuncType ( type.getValue ());
5654
5664
} else {
5655
5665
fnExpr = typeCheckChildIndependently (callExpr->getFn (), Type (),
5656
5666
CTP_CalleeResult, TCC_ForceRecheck,
5657
5667
&listener);
5658
5668
if (!fnExpr)
5659
5669
return true ;
5660
5670
5661
- fnType = fnExpr->getType ()-> getRValueType ( );
5671
+ fnType = getFuncType ( fnExpr->getType ());
5662
5672
}
5663
5673
}
5664
5674
0 commit comments