Skip to content

Commit 0dda779

Browse files
committed
Sema: Always perform shadowing checks for unqualified lookups
The workaround referenced in the FIXME comments no longer appears to be necessary.
1 parent b7acc6d commit 0dda779

File tree

1 file changed

+4
-39
lines changed

1 file changed

+4
-39
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ namespace {
7474
LookupResult &Result;
7575
DeclContext *DC;
7676
NameLookupOptions Options;
77-
bool IsMemberLookup;
7877

7978
/// The vector of found declarations.
8079
SmallVector<ValueDecl *, 4> FoundDecls;
@@ -86,46 +85,13 @@ namespace {
8685

8786
public:
8887
LookupResultBuilder(LookupResult &result, DeclContext *dc,
89-
NameLookupOptions options,
90-
bool isMemberLookup)
91-
: Result(result), DC(dc), Options(options),
92-
IsMemberLookup(isMemberLookup) {
88+
NameLookupOptions options)
89+
: Result(result), DC(dc), Options(options) {
9390
if (dc->getASTContext().isAccessControlDisabled())
9491
Options |= NameLookupFlags::IgnoreAccessControl;
9592
}
9693

97-
/// Determine whether we should filter out the results by removing
98-
/// overridden and shadowed declarations.
99-
/// FIXME: We should *always* do this, but there are weird assumptions
100-
/// about the results of unqualified name lookup, e.g., that a local
101-
/// variable not having a type indicates that it hasn't been seen yet.
102-
bool shouldFilterResults() const {
103-
// Member lookups always filter results.
104-
if (IsMemberLookup) return true;
105-
106-
bool allAreInOtherModules = true;
107-
auto currentModule = DC->getParentModule();
108-
for (const auto &found : Result) {
109-
// We found a member, so we need to filter.
110-
if (found.getBaseDecl() != nullptr)
111-
return true;
112-
113-
// We found something in our own module.
114-
if (found.getValueDecl()->getDeclContext()->getParentModule() ==
115-
currentModule)
116-
allAreInOtherModules = false;
117-
}
118-
119-
// FIXME: Only perform shadowing if we found things from other modules.
120-
// This prevents us from introducing additional type-checking work
121-
// during name lookup.
122-
return allAreInOtherModules;
123-
}
124-
12594
~LookupResultBuilder() {
126-
// Check whether we should do this filtering aat all.
127-
if (!shouldFilterResults()) return;
128-
12995
// Remove any overridden declarations from the found-declarations set.
13096
removeOverriddenDecls(FoundDecls);
13197
removeOverriddenDecls(FoundOuterDecls);
@@ -305,7 +271,7 @@ LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclName name,
305271
convertToUnqualifiedLookupOptions(options));
306272

307273
LookupResult result;
308-
LookupResultBuilder builder(result, dc, options, /*memberLookup*/false);
274+
LookupResultBuilder builder(result, dc, options);
309275
for (auto idx : indices(lookup.Results)) {
310276
const auto &found = lookup.Results[idx];
311277
// Determine which type we looked through to find this result.
@@ -381,8 +347,7 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc,
381347
subOptions &= ~NL_RemoveOverridden;
382348
subOptions &= ~NL_RemoveNonVisible;
383349

384-
LookupResultBuilder builder(result, dc, options,
385-
/*memberLookup*/true);
350+
LookupResultBuilder builder(result, dc, options);
386351
SmallVector<ValueDecl *, 4> lookupResults;
387352
dc->lookupQualified(type, name, subOptions, lookupResults);
388353

0 commit comments

Comments
 (0)