@@ -3753,8 +3753,15 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
37533753 if (decl->isInstanceMember ()) {
37543754 if ((isa<FuncDecl>(decl) && !hasInstanceMethods) ||
37553755 (!isa<FuncDecl>(decl) && !hasInstanceMembers)) {
3756- result.addUnviable (candidate,
3757- MemberLookupResult::UR_InstanceMemberOnType);
3756+ // `AnyObject` has special semantics, so let's just let it be.
3757+ // Otherwise adjust base type and reference kind to make it
3758+ // look as if lookup was done on the instance, that helps
3759+ // with diagnostics.
3760+ auto choice = instanceTy->isAnyObject ()
3761+ ? candidate
3762+ : OverloadChoice (instanceTy, decl,
3763+ FunctionRefKind::SingleApply);
3764+ result.addUnviable (choice, MemberLookupResult::UR_InstanceMemberOnType);
37583765 return ;
37593766 }
37603767
@@ -3926,10 +3933,10 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
39263933 result.addViable (
39273934 OverloadChoice::getDynamicMemberLookup (baseTy, decl, name));
39283935 }
3929- for (auto candidate : subscripts.UnviableCandidates ) {
3930- auto decl = candidate. first .getDecl ();
3936+ for (auto index : indices ( subscripts.UnviableCandidates ) ) {
3937+ auto decl = subscripts. UnviableCandidates [index] .getDecl ();
39313938 auto choice = OverloadChoice::getDynamicMemberLookup (baseTy, decl,name);
3932- result.addUnviable (choice, candidate. second );
3939+ result.addUnviable (choice, subscripts. UnviableReasons [index] );
39333940 }
39343941 }
39353942 }
@@ -4203,9 +4210,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
42034210 break ;
42044211 }
42054212
4213+ SmallVector<Constraint *, 4 > candidates;
42064214 // If we found viable candidates, then we're done!
42074215 if (!result.ViableCandidates .empty ()) {
4208- llvm::SmallVector<Constraint *, 8 > candidates;
42094216 generateConstraints (
42104217 candidates, memberTy, result.ViableCandidates , useDC, locator,
42114218 result.getFavoredIndex (), /* requiresFix=*/ false ,
@@ -4222,11 +4229,24 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
42224229 generateConstraints (candidates, memberTy, outerAlternatives,
42234230 useDC, locator);
42244231 }
4232+ }
4233+
4234+ if (!result.UnviableCandidates .empty ()) {
4235+ // Generate constraints for unvailable choices if they have a fix,
4236+ // and disable them by default, they'd get picked up in the "salvage" mode.
4237+ generateConstraints (
4238+ candidates, memberTy, result.UnviableCandidates , useDC, locator,
4239+ /* favoredChoice=*/ None, /* requiresFix=*/ true ,
4240+ [&](unsigned idx, const OverloadChoice &choice) {
4241+ return fixMemberRef (*this , baseTy, member, choice, locator,
4242+ result.UnviableReasons [idx]);
4243+ });
4244+ }
42254245
4246+ if (!candidates.empty ()) {
42264247 addOverloadSet (candidates, locator);
42274248 return SolutionKind::Solved;
42284249 }
4229-
42304250
42314251 // If the lookup found no hits at all (either viable or unviable), diagnose it
42324252 // as such and try to recover in various ways.
@@ -4238,30 +4258,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
42384258 if (!MissingMembers.insert (locator))
42394259 return SolutionKind::Error;
42404260
4241- if (!result.UnviableCandidates .empty ()) {
4242- SmallVector<OverloadChoice, 8 > choices;
4243- llvm::transform (
4244- result.UnviableCandidates , std::back_inserter (choices),
4245- [](const std::pair<OverloadChoice, MemberLookupResult::UnviableReason>
4246- &candidate) { return candidate.first ; });
4247-
4248- SmallVector<Constraint *, 4 > candidates;
4249- generateConstraints (candidates, memberTy, choices, useDC, locator,
4250- /* favoredChoice=*/ None, /* requiresFix=*/ true ,
4251- [&](unsigned idx, const OverloadChoice &choice) {
4252- return fixMemberRef (
4253- *this , baseTy, member, choice, locator,
4254- result.UnviableCandidates [idx].second );
4255- });
4256-
4257- // If there are any viable "fixed" candidates, let's schedule
4258- // them to be attempted.
4259- if (!candidates.empty ()) {
4260- addOverloadSet (candidates, locator);
4261- return SolutionKind::Solved;
4262- }
4263- }
4264-
42654261 if (baseObjTy->getOptionalObjectType ()) {
42664262 // If the base type was an optional, look through it.
42674263
0 commit comments