@@ -5697,41 +5697,39 @@ ConstraintSystem::simplifyOptionalObjectConstraint(
5697
5697
// If the base type is not optional, let's attempt a fix (if possible)
5698
5698
// and assume that `!` is just not there.
5699
5699
if (!objectTy) {
5700
+ if (!shouldAttemptFixes ())
5701
+ return SolutionKind::Error;
5702
+
5700
5703
// Let's see if we can apply a specific fix here.
5701
- if (shouldAttemptFixes ()) {
5702
- if (optTy->isHole ())
5703
- return SolutionKind::Solved;
5704
+ if (optTy->isHole ())
5705
+ return SolutionKind::Solved;
5706
+
5707
+ auto fnType = optTy->getAs <FunctionType>();
5708
+ if (fnType && fnType->getNumParams () == 0 ) {
5709
+ // For function types with no parameters, let's try to
5710
+ // offer a "make it a call" fix if possible.
5711
+ auto optionalResultType = fnType->getResult ()->getOptionalObjectType ();
5712
+ if (optionalResultType) {
5713
+ if (matchTypes (optionalResultType, second, ConstraintKind::Bind,
5714
+ flags | TMF_ApplyingFix, locator)
5715
+ .isSuccess ()) {
5716
+ auto *fix =
5717
+ InsertExplicitCall::create (*this , getConstraintLocator (locator));
5718
+
5719
+ return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
5720
+ }
5721
+ }
5722
+ }
5704
5723
5705
- auto *fix =
5706
- RemoveUnwrap::create (*this , optTy, getConstraintLocator (locator));
5724
+ auto *fix =
5725
+ RemoveUnwrap::create (*this , optTy, getConstraintLocator (locator));
5707
5726
5708
- if (recordFix (fix))
5709
- return SolutionKind::Error;
5710
-
5711
- // If the fix was successful let's record
5712
- // "fixed" object type and continue.
5713
- objectTy = optTy;
5714
- } else {
5715
- // If fixes are not allowed, no choice but to fail.
5727
+ if (recordFix (fix))
5716
5728
return SolutionKind::Error;
5717
- }
5718
- }
5719
5729
5720
- auto fnType = optTy->getAs <FunctionType>();
5721
- if (shouldAttemptFixes () && fnType && fnType->getNumParams () == 0 ) {
5722
- // For function types with no parameters, let's try to
5723
- // offer a "make it a call" fix if possible.
5724
- auto optionalResultType = fnType->getResult ()->getOptionalObjectType ();
5725
- if (optionalResultType) {
5726
- if (matchTypes (optionalResultType, second, ConstraintKind::Bind,
5727
- flags | TMF_ApplyingFix, locator)
5728
- .isSuccess ()) {
5729
- auto *fix =
5730
- InsertExplicitCall::create (*this , getConstraintLocator (locator));
5731
-
5732
- return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
5733
- }
5734
- }
5730
+ // If the fix was successful let's record
5731
+ // "fixed" object type and continue.
5732
+ objectTy = optTy;
5735
5733
}
5736
5734
5737
5735
// The object type is an lvalue if the optional was.
0 commit comments