@@ -1092,6 +1092,10 @@ enum class DirectlyReferencedTypeLookupFlags {
1092
1092
// / Include results that are members of protocols to which the contextual
1093
1093
// / type conforms.
1094
1094
AllowProtocolMembers = 1 << 2 ,
1095
+
1096
+ // / Include members that would normally be excluded because they come from
1097
+ // / modules that have not been imported directly.
1098
+ IgnoreMissingImports = 1 << 3 ,
1095
1099
};
1096
1100
1097
1101
using DirectlyReferencedTypeLookupOptions =
@@ -2917,6 +2921,10 @@ static DirectlyReferencedTypeDecls directReferencesForUnqualifiedTypeLookup(
2917
2921
DirectlyReferencedTypeLookupFlags::AllowUsableFromInline))
2918
2922
options |= UnqualifiedLookupFlags::IncludeUsableFromInline;
2919
2923
2924
+ if (typeLookupOptions.contains (
2925
+ DirectlyReferencedTypeLookupFlags::IgnoreMissingImports))
2926
+ options |= UnqualifiedLookupFlags::IgnoreMissingImports;
2927
+
2920
2928
// Manually exclude macro expansions here since the source location
2921
2929
// is overridden below.
2922
2930
if (namelookup::isInMacroArgument (dc->getParentSourceFile (), loc))
@@ -2968,14 +2976,10 @@ static DirectlyReferencedTypeDecls directReferencesForUnqualifiedTypeLookup(
2968
2976
}
2969
2977
2970
2978
// / Perform qualified name lookup for types.
2971
- static llvm::TinyPtrVector<TypeDecl *>
2972
- directReferencesForQualifiedTypeLookup (Evaluator &evaluator,
2973
- ASTContext &ctx,
2974
- ArrayRef<TypeDecl *> baseTypes,
2975
- DeclNameRef name,
2976
- DeclContext *dc,
2977
- SourceLoc loc,
2978
- bool allowUsableFromInline=false ) {
2979
+ static llvm::TinyPtrVector<TypeDecl *> directReferencesForQualifiedTypeLookup (
2980
+ Evaluator &evaluator, ASTContext &ctx, ArrayRef<TypeDecl *> baseTypes,
2981
+ DeclNameRef name, DeclContext *dc, SourceLoc loc,
2982
+ DirectlyReferencedTypeLookupOptions typeLookupOptions) {
2979
2983
llvm::TinyPtrVector<TypeDecl *> result;
2980
2984
auto addResults = [&result](ArrayRef<ValueDecl *> found){
2981
2985
for (auto decl : found){
@@ -2990,9 +2994,14 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
2990
2994
SmallVector<ValueDecl *, 4 > members;
2991
2995
auto options = NL_RemoveNonVisible | NL_OnlyTypes;
2992
2996
2993
- if (allowUsableFromInline)
2997
+ if (typeLookupOptions.contains (
2998
+ DirectlyReferencedTypeLookupFlags::AllowUsableFromInline))
2994
2999
options |= NL_IncludeUsableFromInline;
2995
3000
3001
+ if (typeLookupOptions.contains (
3002
+ DirectlyReferencedTypeLookupFlags::IgnoreMissingImports))
3003
+ options |= NL_IgnoreMissingImports;
3004
+
2996
3005
// Look through the type declarations we were given, resolving them down
2997
3006
// to nominal type declarations, module declarations, and
2998
3007
SmallVector<ModuleDecl *, 2 > moduleDecls;
@@ -3031,8 +3040,7 @@ static DirectlyReferencedTypeDecls directReferencesForDeclRefTypeRepr(
3031
3040
// For a qualified identifier, perform qualified name lookup.
3032
3041
result.first = directReferencesForQualifiedTypeLookup (
3033
3042
evaluator, ctx, result.first , repr->getNameRef (), dc, repr->getLoc (),
3034
- options.contains (
3035
- DirectlyReferencedTypeLookupFlags::AllowUsableFromInline));
3043
+ options);
3036
3044
3037
3045
return result;
3038
3046
}
@@ -3419,6 +3427,16 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
3419
3427
DirectlyReferencedTypeDecls referenced = directReferencesForTypeRepr (
3420
3428
evaluator, ctx, typeRepr, ext->getParent (), options);
3421
3429
3430
+ // If there were no results, expand the lookup to include members that are
3431
+ // inaccessible due to missing imports. The missing imports will be diagnosed
3432
+ // elsewhere.
3433
+ if (referenced.first .empty () &&
3434
+ ctx.LangOpts .hasFeature (Feature::MemberImportVisibility)) {
3435
+ options |= DirectlyReferencedTypeLookupFlags::IgnoreMissingImports;
3436
+ referenced = directReferencesForTypeRepr (evaluator, ctx, typeRepr,
3437
+ ext->getParent (), options);
3438
+ }
3439
+
3422
3440
// Resolve those type declarations to nominal type declarations.
3423
3441
SmallVector<ModuleDecl *, 2 > modulesFound;
3424
3442
bool anyObject = false ;
0 commit comments