@@ -3752,33 +3752,45 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3752
3752
}
3753
3753
}
3754
3754
3755
+ void getUnresolvedMemberCompletions (Type T) {
3756
+ if (!T->getNominalOrBoundGenericNominal ())
3757
+ return ;
3758
+
3759
+ // We can only say .foo where foo is a static member of the contextual
3760
+ // type and has the same type (or if the member is a function, then the
3761
+ // same result type) as the contextual type.
3762
+ FilteredDeclConsumer consumer (*this , [=](ValueDecl *VD, DeclVisibilityKind reason) {
3763
+ if (!VD->hasInterfaceType ()) {
3764
+ TypeResolver->resolveDeclSignature (VD);
3765
+ if (!VD->hasInterfaceType ())
3766
+ return false ;
3767
+ }
3768
+
3769
+ auto declTy = VD->getInterfaceType ();
3770
+ while (auto FT = declTy->getAs <AnyFunctionType>())
3771
+ declTy = FT->getResult ();
3772
+ return declTy->isEqual (T);
3773
+ });
3774
+
3775
+ auto baseType = MetatypeType::get (T);
3776
+ llvm::SaveAndRestore<LookupKind> SaveLook (Kind, LookupKind::ValueExpr);
3777
+ llvm::SaveAndRestore<Type> SaveType (ExprType, baseType);
3778
+ llvm::SaveAndRestore<bool > SaveUnresolved (IsUnresolvedMember, true );
3779
+ lookupVisibleMemberDecls (consumer, baseType, CurrDeclContext,
3780
+ TypeResolver.get (),
3781
+ /* includeInstanceMembers=*/ false );
3782
+ }
3783
+
3755
3784
void getUnresolvedMemberCompletions (ArrayRef<Type> Types) {
3756
3785
NeedLeadingDot = !HaveDot;
3757
3786
for (auto T : Types) {
3758
- if (T && T->getNominalOrBoundGenericNominal ()) {
3759
- // We can only say .foo where foo is a static member of the contextual
3760
- // type and has the same type (or if the member is a function, then the
3761
- // same result type) as the contextual type.
3762
- FilteredDeclConsumer consumer (*this , [=](ValueDecl *VD, DeclVisibilityKind reason) {
3763
- if (!VD->hasInterfaceType ()) {
3764
- TypeResolver->resolveDeclSignature (VD);
3765
- if (!VD->hasInterfaceType ())
3766
- return false ;
3767
- }
3768
-
3769
- auto declTy = VD->getInterfaceType ();
3770
- while (auto FT = declTy->getAs <AnyFunctionType>())
3771
- declTy = FT->getResult ();
3772
- return declTy->isEqual (T);
3773
- });
3774
-
3775
- auto baseType = MetatypeType::get (T);
3776
- llvm::SaveAndRestore<LookupKind> SaveLook (Kind, LookupKind::ValueExpr);
3777
- llvm::SaveAndRestore<Type> SaveType (ExprType, baseType);
3778
- llvm::SaveAndRestore<bool > SaveUnresolved (IsUnresolvedMember, true );
3779
- lookupVisibleMemberDecls (consumer, baseType, CurrDeclContext,
3780
- TypeResolver.get (),
3781
- /* includeInstanceMembers=*/ false );
3787
+ if (T) {
3788
+ // FIXME: we should also include .some/.none from optional itself but
3789
+ // getUnresolvedMemberCompletions doesn't ever return them since the
3790
+ // interface type in the FilteredDeclConsumer will not match the bound
3791
+ // generic type expected.
3792
+ T = T->lookThroughAllOptionalTypes ();
3793
+ getUnresolvedMemberCompletions (T);
3782
3794
}
3783
3795
}
3784
3796
}
0 commit comments