Skip to content

Commit 0a39e7d

Browse files
committed
[CSApply] Move the variable type check into the lookup filter call
1 parent aa565f5 commit 0a39e7d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

lib/Sema/CSApply.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,9 +2476,10 @@ namespace {
24762476
memberName,
24772477
defaultMemberLookupOptions);
24782478

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) {
24822483
if (auto member = entry.getValueDecl()) {
24832484
if (isa<FuncDecl>(member))
24842485
return false;
@@ -2487,6 +2488,10 @@ namespace {
24872488
if (auto EED = dyn_cast<EnumElementDecl>(member)) {
24882489
return !EED->hasAssociatedValues();
24892490
}
2491+
if (auto VD = dyn_cast<VarDecl>(member)) {
2492+
auto baseType = DSCE->getType()->lookThroughAllOptionalTypes();
2493+
return VD->getInterfaceType()->isEqual(baseType);
2494+
}
24902495
}
24912496

24922497
return true;
@@ -2497,15 +2502,7 @@ namespace {
24972502
}
24982503

24992504
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
25092506
auto baseTyName = baseTy->getCanonicalType().getString();
25102507
auto baseTyUnwrappedName = baseTyUnwrapped->getString();
25112508
auto loc = DSCE->getLoc();

0 commit comments

Comments
 (0)