@@ -2476,9 +2476,10 @@ namespace {
2476
2476
memberName,
2477
2477
defaultMemberLookupOptions);
2478
2478
2479
- // Filter out any functions, instance members or enum cases with
2480
- // associated values.
2481
- results.filter ([](const LookupResultEntry entry, bool isOuter) {
2479
+ // Filter out any functions, instance members, enum cases with
2480
+ // associated values or variables whose type does not match the
2481
+ // contextual type.
2482
+ results.filter ([&](const LookupResultEntry entry, bool isOuter) {
2482
2483
if (auto member = entry.getValueDecl ()) {
2483
2484
if (isa<FuncDecl>(member))
2484
2485
return false ;
@@ -2487,6 +2488,10 @@ namespace {
2487
2488
if (auto EED = dyn_cast<EnumElementDecl>(member)) {
2488
2489
return !EED->hasAssociatedValues ();
2489
2490
}
2491
+ if (auto VD = dyn_cast<VarDecl>(member)) {
2492
+ auto baseType = DSCE->getType ()->lookThroughAllOptionalTypes ();
2493
+ return VD->getInterfaceType ()->isEqual (baseType);
2494
+ }
2490
2495
}
2491
2496
2492
2497
return true ;
@@ -2497,15 +2502,7 @@ namespace {
2497
2502
}
2498
2503
2499
2504
if (auto member = results.front ().getValueDecl ()) {
2500
- // If this is a variable whose type does not match the base type
2501
- // of the target then ignore it.
2502
- if (auto VD = dyn_cast<VarDecl>(member)) {
2503
- auto baseType = DSCE->getType ()->lookThroughAllOptionalTypes ();
2504
- if (!VD->getInterfaceType ()->isEqual (baseType))
2505
- return ;
2506
- }
2507
-
2508
- // Emit a diagnostic with some fixits
2505
+ // Emit a diagnostic with some fix-its
2509
2506
auto baseTyName = baseTy->getCanonicalType ().getString ();
2510
2507
auto baseTyUnwrappedName = baseTyUnwrapped->getString ();
2511
2508
auto loc = DSCE->getLoc ();
0 commit comments