mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #75158 from tshortli/member-import-visibility-package
AST: Add a `IgnoreMissingImports` option to name lookup
This commit is contained in:
@@ -10454,30 +10454,45 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
|
||||
if (result.ViableCandidates.empty() && result.UnviableCandidates.empty() &&
|
||||
includeInaccessibleMembers) {
|
||||
NameLookupOptions lookupOptions = defaultMemberLookupOptions;
|
||||
|
||||
// Ignore access control so we get candidates that might have been missed
|
||||
// before.
|
||||
lookupOptions |= NameLookupFlags::IgnoreAccessControl;
|
||||
|
||||
auto lookup =
|
||||
TypeChecker::lookupMember(DC, instanceTy, memberName,
|
||||
memberLoc, lookupOptions);
|
||||
for (auto entry : lookup) {
|
||||
auto *cand = entry.getValueDecl();
|
||||
// Local function that looks up additional candidates using the given lookup
|
||||
// options, recording the results as unviable candidates.
|
||||
auto lookupUnviable =
|
||||
[&](NameLookupOptions lookupOptions,
|
||||
MemberLookupResult::UnviableReason reason) -> bool {
|
||||
auto lookup = TypeChecker::lookupMember(DC, instanceTy, memberName,
|
||||
memberLoc, lookupOptions);
|
||||
for (auto entry : lookup) {
|
||||
auto *cand = entry.getValueDecl();
|
||||
|
||||
// If the result is invalid, skip it.
|
||||
if (cand->isInvalid()) {
|
||||
result.markErrorAlreadyDiagnosed();
|
||||
return result;
|
||||
// If the result is invalid, skip it.
|
||||
if (cand->isInvalid()) {
|
||||
result.markErrorAlreadyDiagnosed();
|
||||
break;
|
||||
}
|
||||
|
||||
if (excludedDynamicMembers.count(cand))
|
||||
continue;
|
||||
|
||||
result.addUnviable(getOverloadChoice(cand, /*isBridged=*/false,
|
||||
/*isUnwrappedOptional=*/false),
|
||||
reason);
|
||||
}
|
||||
|
||||
if (excludedDynamicMembers.count(cand))
|
||||
continue;
|
||||
return !lookup.empty();
|
||||
};
|
||||
|
||||
result.addUnviable(getOverloadChoice(cand, /*isBridged=*/false,
|
||||
/*isUnwrappedOptional=*/false),
|
||||
MemberLookupResult::UR_Inaccessible);
|
||||
}
|
||||
// Ignore access control so we get candidates that might have been missed
|
||||
// before.
|
||||
if (lookupUnviable(lookupOptions | NameLookupFlags::IgnoreAccessControl,
|
||||
MemberLookupResult::UR_Inaccessible))
|
||||
return result;
|
||||
|
||||
// Ignore missing import statements in order to find more candidates that
|
||||
// might have been missed before.
|
||||
if (lookupUnviable(lookupOptions | NameLookupFlags::IgnoreMissingImports,
|
||||
MemberLookupResult::UR_MissingImport))
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -10678,9 +10693,11 @@ static ConstraintFix *fixMemberRef(
|
||||
}
|
||||
|
||||
case MemberLookupResult::UR_Inaccessible:
|
||||
case MemberLookupResult::UR_MissingImport:
|
||||
assert(choice.isDecl());
|
||||
return AllowInaccessibleMember::create(cs, baseTy, choice.getDecl(),
|
||||
memberName, locator);
|
||||
return AllowInaccessibleMember::create(
|
||||
cs, baseTy, choice.getDecl(), memberName, locator,
|
||||
*reason == MemberLookupResult::UR_MissingImport);
|
||||
|
||||
case MemberLookupResult::UR_UnavailableInExistential: {
|
||||
return choice.isDecl()
|
||||
|
||||
Reference in New Issue
Block a user