Skip to content

Scope map fixes #5289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/AST/ASTScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,9 +1420,14 @@ SourceRange ASTScope::getSourceRangeImpl() const {
return typeDecl->getSourceRange();

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

case ASTScopeKind::ExtensionGenericParams:
case ASTScopeKind::ExtensionGenericParams: {
// If the source range containing the extension parameters is empty,
// do nothing.
SourceRange range = getSourceRangeImpl();
if (range.Start == range.End)
break;

// Bind this extension, if we haven't done so already.
if (!extension->getExtendedType())
if (auto resolver = extension->getASTContext().getLazyResolver())
Expand All @@ -1821,6 +1832,7 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
result.push_back(param);
}
break;
}

case ASTScopeKind::GenericParams:
result.push_back(genericParams.params->getParams()[genericParams.index]);
Expand Down Expand Up @@ -1873,6 +1885,8 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
break;

case ASTScopeKind::PatternInitializer:
// FIXME: This causes recursion that we cannot yet handle.
#if false
// 'self' is available within the pattern initializer of a 'lazy' variable.
if (auto singleVar = patternBinding.decl->getSingleVar()) {
if (singleVar->getAttrs().hasAttribute<LazyAttr>() &&
Expand All @@ -1890,6 +1904,7 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
result.push_back(self);
}
}
#endif
break;

case ASTScopeKind::Closure:
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,7 @@ ParserResult<Stmt> Parser::parseStmtForCStyle(SourceLoc ForLoc,
// If we're missing a semicolon, try to recover.
if (Tok.isNot(tok::semi)) {
// Provide a reasonable default location for the first semicolon.
Semi1Loc = Tok.getLoc();
Semi1Loc = PreviousLoc;

if (auto *BS = ConvertClosureToBraceStmt(First.getPtrOrNull(), Context)) {
// We have seen:
Expand Down
4 changes: 3 additions & 1 deletion test/NameBinding/scope_map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ class LazyProperties {
// CHECK-SEARCHES-NEXT: FileUnit file="{{.*}}scope_map.swift"
// CHECK-SEARCHES-NEXT: ClassDecl name=LazyProperties
// CHECK-SEARCHES-NEXT: Initializer PatternBinding {{.*}} #0
// CHECK-SEARCHES-NEXT: Local bindings: self

// FIXME: Re-enable the binding below
// CHECK-SEARCHES-NOT: Local bindings: self

// CHECK-SEARCHES-LABEL: ***Complete scope map***
// CHECK-SEARCHES-NEXT: SourceFile {{.*}} '{{.*}}scope_map.swift' [1:1 - [[EOF:[0-9]+:[0-9]+]]] unexpanded
Expand Down
8 changes: 7 additions & 1 deletion test/NameBinding/scope_map_lookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ extension P2 {
}
}

#if false
// Lazy properties
class LazyProperties {
init() {
lazy var localvar = 42 // expected-error {{lazy is only valid for members of a struct or class}} {{5-10=}}
lazy var localvar = 42 // FIXME: should error {{lazy is only valid for members of a struct or class}} {{5-10=}}
localvar += 1
_ = localvar
}
Expand All @@ -57,6 +58,7 @@ class LazyProperties {

lazy var prop5: Int = { self.value + 1 }()
}
#endif

// Protocol extensions.
// Extending via a superclass constraint.
Expand Down Expand Up @@ -110,6 +112,10 @@ protocol Fooable {
var foo: Foo { get }
}

// The extension below once caused infinite recursion.
struct S<T> // expected-error{{expected '{' in struct}}
extension S // expected-error{{expected '{' in extension}}

let a = b ; let b = a // expected-error{{could not infer type for 'a'}}
// expected-error@-1 {{'a' used within its own type}}
// FIXME: That second error is bogus.
1 change: 1 addition & 0 deletions test/Parse/toplevel_library_invalid.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-parse-verify-swift -parse-as-library
// RUN: %target-parse-verify-swift -parse-as-library -enable-astscope-lookup

let x = 42 // expected-note{{did you mean 'x'?}}
x + x; // expected-error {{expressions are not allowed at the top level}} expected-warning {{result of operator '+' is unused}}
Expand Down