@@ -3734,49 +3734,72 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
3734
3734
3735
3735
// If the lookup found no hits at all (either viable or unviable), diagnose it
3736
3736
// as such and try to recover in various ways.
3737
- if (shouldAttemptFixes () && baseObjTy->getOptionalObjectType ()) {
3738
- // If the base type was an optional, look through it.
3739
-
3740
- // If the base type is optional because we haven't chosen to force an
3741
- // implicit optional, don't try to fix it. The IUO will be forced instead.
3742
- if (auto dotExpr = dyn_cast<UnresolvedDotExpr>(locator->getAnchor ())) {
3743
- auto baseExpr = dotExpr->getBase ();
3744
- auto resolvedOverload = getResolvedOverloadSets ();
3745
- while (resolvedOverload) {
3746
- if (resolvedOverload->Locator ->getAnchor () == baseExpr) {
3747
- if (resolvedOverload->Choice .isImplicitlyUnwrappedValueOrReturnValue ())
3748
- return SolutionKind::Error;
3749
- break ;
3737
+ if (shouldAttemptFixes ()) {
3738
+ if (baseObjTy->getOptionalObjectType ()) {
3739
+ // If the base type was an optional, look through it.
3740
+
3741
+ // If the base type is optional because we haven't chosen to force an
3742
+ // implicit optional, don't try to fix it. The IUO will be forced instead.
3743
+ if (auto dotExpr = dyn_cast<UnresolvedDotExpr>(locator->getAnchor ())) {
3744
+ auto baseExpr = dotExpr->getBase ();
3745
+ auto resolvedOverload = getResolvedOverloadSets ();
3746
+ while (resolvedOverload) {
3747
+ if (resolvedOverload->Locator ->getAnchor () == baseExpr) {
3748
+ if (resolvedOverload->Choice
3749
+ .isImplicitlyUnwrappedValueOrReturnValue ())
3750
+ return SolutionKind::Error;
3751
+ break ;
3752
+ }
3753
+ resolvedOverload = resolvedOverload->Previous ;
3750
3754
}
3751
- resolvedOverload = resolvedOverload->Previous ;
3752
3755
}
3756
+
3757
+ // The result of the member access can either be the expected member type
3758
+ // (for '!' or optional members with '?'), or the original member type
3759
+ // with one extra level of optionality ('?' with non-optional members).
3760
+ auto innerTV = createTypeVariable (locator, TVO_CanBindToLValue);
3761
+ Type optTy = getTypeChecker ().getOptionalType (
3762
+ locator->getAnchor ()->getSourceRange ().Start , innerTV);
3763
+ SmallVector<Constraint *, 2 > optionalities;
3764
+ auto nonoptionalResult = Constraint::createFixed (
3765
+ *this , ConstraintKind::Bind,
3766
+ UnwrapOptionalBase::create (*this , member, locator), innerTV, memberTy,
3767
+ locator);
3768
+ auto optionalResult = Constraint::createFixed (
3769
+ *this , ConstraintKind::Bind,
3770
+ UnwrapOptionalBase::createWithOptionalResult (*this , member, locator),
3771
+ optTy, memberTy, locator);
3772
+ optionalities.push_back (nonoptionalResult);
3773
+ optionalities.push_back (optionalResult);
3774
+ addDisjunctionConstraint (optionalities, locator);
3775
+
3776
+ // Look through one level of optional.
3777
+ addValueMemberConstraint (baseObjTy->getOptionalObjectType (), member,
3778
+ innerTV, useDC, functionRefKind,
3779
+ outerAlternatives, locator);
3780
+ return SolutionKind::Solved;
3753
3781
}
3754
3782
3755
- // The result of the member access can either be the expected member type
3756
- // (for '!' or optional members with '?'), or the original member type with
3757
- // one extra level of optionality ('?' with non-optional members).
3758
- auto innerTV =
3759
- createTypeVariable (locator, TVO_CanBindToLValue);
3760
- Type optTy = getTypeChecker ().getOptionalType (
3761
- locator->getAnchor ()->getSourceRange ().Start , innerTV);
3762
- SmallVector<Constraint *, 2 > optionalities;
3763
- auto nonoptionalResult = Constraint::createFixed (
3764
- *this , ConstraintKind::Bind,
3765
- UnwrapOptionalBase::create (*this , member, locator), innerTV, memberTy,
3766
- locator);
3767
- auto optionalResult = Constraint::createFixed (
3768
- *this , ConstraintKind::Bind,
3769
- UnwrapOptionalBase::createWithOptionalResult (*this , member, locator),
3770
- optTy, memberTy, locator);
3771
- optionalities.push_back (nonoptionalResult);
3772
- optionalities.push_back (optionalResult);
3773
- addDisjunctionConstraint (optionalities, locator);
3774
-
3775
- // Look through one level of optional.
3776
- addValueMemberConstraint (baseObjTy->getOptionalObjectType (), member,
3777
- innerTV, useDC, functionRefKind, outerAlternatives,
3778
- locator);
3779
- return SolutionKind::Solved;
3783
+ if (auto *funcType = baseTy->getAs <FunctionType>()) {
3784
+ // We can't really suggest anything useful unless
3785
+ // function takes no arguments, otherwise it
3786
+ // would make sense to report this a missing member.
3787
+ if (funcType->getNumParams () == 0 ) {
3788
+ auto *fix = InsertExplicitCall::create (*this , locator);
3789
+ if (recordFix (fix))
3790
+ return SolutionKind::Error;
3791
+
3792
+ auto result = simplifyMemberConstraint (
3793
+ kind, funcType->getResult (), member, memberTy, useDC,
3794
+ functionRefKind, outerAlternatives, flags, locatorB);
3795
+
3796
+ // If there is indeed a member with given name in result type
3797
+ // let's return, otherwise let's fall-through and report
3798
+ // this problem as a missing member.
3799
+ if (result == SolutionKind::Solved)
3800
+ return result;
3801
+ }
3802
+ }
3780
3803
}
3781
3804
return SolutionKind::Error;
3782
3805
}
@@ -5439,6 +5462,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
5439
5462
return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
5440
5463
}
5441
5464
5465
+ case FixKind::InsertCall:
5442
5466
case FixKind::ExplicitlyEscaping:
5443
5467
case FixKind::CoerceToCheckedCast:
5444
5468
case FixKind::RelabelArguments:
0 commit comments