@@ -669,11 +669,9 @@ static bool collectPossibleCalleesForUnresolvedMember(
669669 SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
670670 auto currModule = DC.getParentModule ();
671671
672- // Get the context of the expression itself.
673- ExprContextInfo contextInfo (&DC, unresolvedMemberExpr);
674- for (auto expectedTy : contextInfo.getPossibleTypes ()) {
672+ auto collectMembers = [&](Type expectedTy) {
675673 if (!expectedTy->mayHaveMembers ())
676- continue ;
674+ return ;
677675 SmallVector<FunctionTypeAndDecl, 2 > members;
678676 collectPossibleCalleesByQualifiedLookup (DC, MetatypeType::get (expectedTy),
679677 unresolvedMemberExpr->getName (),
@@ -683,6 +681,16 @@ static bool collectPossibleCalleesForUnresolvedMember(
683681 member.Decl ))
684682 candidates.push_back (member);
685683 }
684+ };
685+
686+ // Get the context of the expression itself.
687+ ExprContextInfo contextInfo (&DC, unresolvedMemberExpr);
688+ for (auto expectedTy : contextInfo.getPossibleTypes ()) {
689+ collectMembers (expectedTy);
690+ // If this is an optional type, let's also check its base type.
691+ if (auto baseTy = expectedTy->getOptionalObjectType ()) {
692+ collectMembers (baseTy->lookThroughAllOptionalTypes ());
693+ }
686694 }
687695 return !candidates.empty ();
688696}
0 commit comments