Skip to content

Commit

Permalink
Sema: Check for re-declarations in local context in CheckRedeclaratio…
Browse files Browse the repository at this point in the history
…nRequest
  • Loading branch information
slavapestov committed Sep 30, 2020
1 parent c56ab07 commit d585838
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,11 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
// FIXME: Should restrict this to the source file we care about.
DeclContext *currentDC = current->getDeclContext();
SourceFile *currentFile = currentDC->getParentSourceFile();
if (!currentFile || currentDC->isLocalContext())
if (!currentFile)
return std::make_tuple<>();

auto &ctx = current->getASTContext();

// Find other potential definitions.
SmallVector<ValueDecl *, 4> otherDefinitions;
if (currentDC->isTypeContext()) {
Expand All @@ -500,7 +502,17 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
auto found = nominal->lookupDirect(current->getBaseName());
otherDefinitions.append(found.begin(), found.end());
}
} else if (currentDC->isLocalContext()) {
if (ctx.LangOpts.DisableParserLookup) {
if (!current->isImplicit()) {
ASTScope::lookupLocalDecls(currentFile, current->getBaseName(),
current->getLoc(),
/*stopAfterInnermostBraceStmt=*/true,
otherDefinitions);
}
}
} else {
assert(currentDC->isModuleScopeContext());
// Look within a module context.
currentFile->getParentModule()->lookupValue(current->getBaseName(),
NLKind::QualifiedLookup,
Expand All @@ -512,7 +524,6 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
OverloadSignature currentSig = current->getOverloadSignature();
CanType currentSigType = current->getOverloadSignatureType();
ModuleDecl *currentModule = current->getModuleContext();
auto &ctx = current->getASTContext();
for (auto other : otherDefinitions) {
// Skip invalid declarations and ourselves.
//
Expand Down Expand Up @@ -547,7 +558,8 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
// shadows a non-private one, but only in the file where the shadowing
// happens. We will warn on conflicting non-private declarations in both
// files.
if (!other->isAccessibleFrom(currentDC))
if (!currentDC->isLocalContext() &&
!other->isAccessibleFrom(currentDC))
continue;

// Skip invalid declarations.
Expand Down

0 comments on commit d585838

Please sign in to comment.