Skip to content

Commit 33d37c5

Browse files
committed
[Scope map] Cope with extensions that have bogus {} locations.
1 parent 8850e12 commit 33d37c5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/AST/ASTScope.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,14 @@ SourceRange ASTScope::getSourceRangeImpl() const {
14201420
return typeDecl->getSourceRange();
14211421

14221422
case ASTScopeKind::ExtensionGenericParams: {
1423-
// The generic parameters of an extension are available from the trailing
1423+
// The generic parameters of an extension are available from the ':' of
1424+
// the inheritance clause (if available), or else that from the
14241425
// 'where' (if present) or from the start of the body.
1426+
// FIXME: Approximating the ':' with the start of the first inherited entry.
14251427
SourceLoc startLoc;
1428+
if (!extension->getInherited().empty() &&
1429+
extension->getInherited().front().getSourceRange().Start.isValid())
1430+
startLoc = extension->getInherited().front().getSourceRange().Start;
14261431
if (auto trailingWhere = extension->getTrailingWhereClause())
14271432
startLoc = trailingWhere->getWhereLoc();
14281433
else
@@ -1807,7 +1812,13 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
18071812
// No local declarations.
18081813
break;
18091814

1810-
case ASTScopeKind::ExtensionGenericParams:
1815+
case ASTScopeKind::ExtensionGenericParams: {
1816+
// If the source range containing the extension parameters is empty,
1817+
// do nothing.
1818+
SourceRange range = getSourceRangeImpl();
1819+
if (range.Start == range.End)
1820+
break;
1821+
18111822
// Bind this extension, if we haven't done so already.
18121823
if (!extension->getExtendedType())
18131824
if (auto resolver = extension->getASTContext().getLazyResolver())
@@ -1821,6 +1832,7 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
18211832
result.push_back(param);
18221833
}
18231834
break;
1835+
}
18241836

18251837
case ASTScopeKind::GenericParams:
18261838
result.push_back(genericParams.params->getParams()[genericParams.index]);

test/NameBinding/scope_map_lookup.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ protocol Fooable {
112112
var foo: Foo { get }
113113
}
114114

115+
// The extension below once caused infinite recursion.
116+
struct S<T> // expected-error{{expected '{' in struct}}
117+
extension S // expected-error{{expected '{' in extension}}
118+
115119
let a = b ; let b = a // expected-error{{could not infer type for 'a'}}
116120
// expected-error@-1 {{'a' used within its own type}}
117121
// FIXME: That second error is bogus.

0 commit comments

Comments
 (0)