Skip to content

Commit fbb97b9

Browse files
committed
AST: Fix an assertion in UnqualifiedLookup to use CharSourceRanges
1 parent 996100c commit fbb97b9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/Basic/STLExtras.h"
2828
#include "swift/Basic/SourceManager.h"
2929
#include "swift/Basic/Statistic.h"
30+
#include "swift/Parse/Lexer.h"
3031
#include "llvm/ADT/DenseMap.h"
3132
#include "llvm/ADT/TinyPtrVector.h"
3233
#include "llvm/Support/Debug.h"
@@ -147,7 +148,7 @@ namespace {
147148

148149
#pragma mark context-based lookup declarations
149150

150-
bool isOutsideBodyOfFunction(const AbstractFunctionDecl *const AFD) const;
151+
bool isInsideBodyOfFunction(const AbstractFunctionDecl *const AFD) const;
151152

152153
/// For diagnostic purposes, move aside the unavailables, and put
153154
/// them back as a last-ditch effort.
@@ -319,11 +320,11 @@ void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext(
319320

320321
#pragma mark context-based lookup definitions
321322

322-
bool UnqualifiedLookupFactory::isOutsideBodyOfFunction(
323+
bool UnqualifiedLookupFactory::isInsideBodyOfFunction(
323324
const AbstractFunctionDecl *const AFD) const {
324-
return !AFD->isImplicit() && Loc.isValid() &&
325-
AFD->getBodySourceRange().isValid() &&
326-
!SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc);
325+
auto range = Lexer::getCharSourceRangeFromSourceRange(
326+
SM, AFD->getBodySourceRange());
327+
return range.contains(Loc);
327328
}
328329

329330
void UnqualifiedLookupFactory::ResultFinderForTypeContext::findResults(
@@ -635,7 +636,7 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers(
635636
NominalTypeDecl *const nominal) {
636637
if (candidateSelfDC) {
637638
if (auto *afd = dyn_cast<AbstractFunctionDecl>(candidateSelfDC)) {
638-
assert(!factory.isOutsideBodyOfFunction(afd) && "Should be inside");
639+
assert(factory.isInsideBodyOfFunction(afd) && "Should be inside");
639640
}
640641
}
641642

0 commit comments

Comments
 (0)