[Scope map] A local property name is in scope within its own accessors.

While the use of a local property from within its own accessors is a
bit dubious, Swift 3 only warned on it, so model the existing lookup
behavior in the scope map.
This commit is contained in:
Doug Gregor
2016-09-14 09:16:23 -07:00
parent 40445be66a
commit ac93c52c96
6 changed files with 62 additions and 63 deletions

View File

@@ -918,26 +918,20 @@ VarDecl *PatternBindingEntry::getAnchoringVarDecl() const {
return variables[0];
}
SourceRange PatternBindingEntry::getSourceRange() const {
ASTContext *ctx = nullptr;
SourceRange PatternBindingEntry::getSourceRange(bool omitAccessors) const {
// Patterns end at the initializer, if present.
SourceLoc endLoc = getOrigInitRange().End;
SourceLoc endLoc;
getPattern()->forEachVariable([&](VarDecl *var) {
auto accessorsEndLoc = var->getBracesRange().End;
if (accessorsEndLoc.isValid()) {
endLoc = accessorsEndLoc;
if (!ctx) ctx = &var->getASTContext();
}
});
// If we're not banned from handling accessors, they follow the initializer.
if (!omitAccessors) {
getPattern()->forEachVariable([&](VarDecl *var) {
auto accessorsEndLoc = var->getBracesRange().End;
if (accessorsEndLoc.isValid())
endLoc = accessorsEndLoc;
});
}
// Check the initializer.
SourceLoc initEndLoc = getOrigInitRange().End;
if (initEndLoc.isValid() &&
(endLoc.isInvalid() ||
(ctx && ctx->SourceMgr.isBeforeInBuffer(endLoc, initEndLoc))))
endLoc = initEndLoc;
// Check the pattern.
// If we didn't find an end yet, check the pattern.
if (endLoc.isInvalid())
endLoc = getPattern()->getEndLoc();