Skip to content

Commit 1e4eca8

Browse files
committed
AST: More robust ASTScope for generic parameter list of a protocol
Don't look at the source locations, because they're fake; just make the generic parameter `Self` visible inside the body of the protocol instead.
1 parent c498f37 commit 1e4eca8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/AST/ASTScope.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,13 @@ SourceRange ASTScope::getSourceRangeImpl() const {
14391439
return cast<NominalTypeDecl>(iterableDeclContext)->getBraces();
14401440

14411441
case ASTScopeKind::GenericParams:
1442+
// A protocol's generic parameter list is not written in source, and
1443+
// is visible from the start of the body.
1444+
if (auto *protoDecl = dyn_cast<ProtocolDecl>(genericParams.decl)) {
1445+
return SourceRange(protoDecl->getBraces().Start,
1446+
protoDecl->getEndLoc());
1447+
}
1448+
14421449
// Explicitly-written generic parameters are in scope following their
14431450
// definition.
14441451
return SourceRange(genericParams.params->getParams()[genericParams.index]

0 commit comments

Comments
 (0)