@@ -10454,30 +10454,45 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
10454
10454
if (result.ViableCandidates.empty() && result.UnviableCandidates.empty() &&
10455
10455
includeInaccessibleMembers) {
10456
10456
NameLookupOptions lookupOptions = defaultMemberLookupOptions;
10457
-
10458
- // Ignore access control so we get candidates that might have been missed
10459
- // before.
10460
- lookupOptions |= NameLookupFlags::IgnoreAccessControl;
10461
10457
10462
- auto lookup =
10463
- TypeChecker::lookupMember(DC, instanceTy, memberName,
10464
- memberLoc, lookupOptions);
10465
- for (auto entry : lookup) {
10466
- auto *cand = entry.getValueDecl();
10458
+ // Local function that looks up additional candidates using the given lookup
10459
+ // options, recording the results as unviable candidates.
10460
+ auto lookupUnviable =
10461
+ [&](NameLookupOptions lookupOptions,
10462
+ MemberLookupResult::UnviableReason reason) -> bool {
10463
+ auto lookup = TypeChecker::lookupMember(DC, instanceTy, memberName,
10464
+ memberLoc, lookupOptions);
10465
+ for (auto entry : lookup) {
10466
+ auto *cand = entry.getValueDecl();
10467
+
10468
+ // If the result is invalid, skip it.
10469
+ if (cand->isInvalid()) {
10470
+ result.markErrorAlreadyDiagnosed();
10471
+ break;
10472
+ }
10473
+
10474
+ if (excludedDynamicMembers.count(cand))
10475
+ continue;
10467
10476
10468
- // If the result is invalid, skip it.
10469
- if (cand->isInvalid()) {
10470
- result.markErrorAlreadyDiagnosed();
10471
- return result;
10477
+ result.addUnviable(getOverloadChoice(cand, /*isBridged=*/false,
10478
+ /*isUnwrappedOptional=*/false),
10479
+ reason);
10472
10480
}
10473
10481
10474
- if (excludedDynamicMembers.count(cand))
10475
- continue ;
10482
+ return !lookup.empty();
10483
+ } ;
10476
10484
10477
- result.addUnviable(getOverloadChoice(cand, /*isBridged=*/false,
10478
- /*isUnwrappedOptional=*/false),
10479
- MemberLookupResult::UR_Inaccessible);
10480
- }
10485
+ // Ignore access control so we get candidates that might have been missed
10486
+ // before.
10487
+ if (lookupUnviable(lookupOptions | NameLookupFlags::IgnoreAccessControl,
10488
+ MemberLookupResult::UR_Inaccessible))
10489
+ return result;
10490
+
10491
+ // Ignore missing import statements in order to find more candidates that
10492
+ // might have been missed before.
10493
+ if (lookupUnviable(lookupOptions | NameLookupFlags::IgnoreMissingImports,
10494
+ MemberLookupResult::UR_MissingImport))
10495
+ return result;
10481
10496
}
10482
10497
10483
10498
return result;
@@ -10678,9 +10693,11 @@ static ConstraintFix *fixMemberRef(
10678
10693
}
10679
10694
10680
10695
case MemberLookupResult::UR_Inaccessible:
10696
+ case MemberLookupResult::UR_MissingImport:
10681
10697
assert(choice.isDecl());
10682
- return AllowInaccessibleMember::create(cs, baseTy, choice.getDecl(),
10683
- memberName, locator);
10698
+ return AllowInaccessibleMember::create(
10699
+ cs, baseTy, choice.getDecl(), memberName, locator,
10700
+ *reason == MemberLookupResult::UR_MissingImport);
10684
10701
10685
10702
case MemberLookupResult::UR_UnavailableInExistential: {
10686
10703
return choice.isDecl()
0 commit comments