Skip to content

Commit 18dc8d4

Browse files
committed
AST: Fix ASTScope lookup for invalid extensions
If there are no braces, the start and end location of the range is the same token, so don't create a TypeOrExtensionBody scope at all. NFC for now, but this problem causes some tests to fail once we enable cycle diagnostics.
1 parent df633ff commit 18dc8d4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/AST/ASTScope.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,14 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
877877

878878
// If we already have a scope of the (possible) generic parameters,
879879
// add the body.
880-
if (parent->getKind() == ASTScopeKind::ExtensionGenericParams)
880+
if (parent->getKind() == ASTScopeKind::ExtensionGenericParams) {
881+
// If there is no body because we have an invalid extension written
882+
// without braces in the source, just return.
883+
if (ext->getBraces().Start == ext->getBraces().End)
884+
return nullptr;
885+
881886
return new (ctx) ASTScope(parent, cast<IterableDeclContext>(ext));
887+
}
882888

883889
// Otherwise, form the extension's generic parameters scope.
884890
return new (ctx) ASTScope(parent, ext);

0 commit comments

Comments
 (0)