Skip to content

[Scope map] Explicitly model the scope of a function body. #4660

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 1 commit into from
Sep 7, 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
18 changes: 13 additions & 5 deletions include/swift/AST/ASTScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ enum class ASTScopeKind : uint8_t {
AbstractFunctionParams,
/// The default argument for a parameter.
DefaultArgument,
/// The body of a function.
AbstractFunctionBody,
/// A specific pattern binding.
PatternBinding,
/// The scope introduced for an initializer of a pattern binding.
Expand Down Expand Up @@ -186,7 +188,8 @@ class ASTScope {
unsigned index;
} genericParams;

/// An abstract function, for \c kind == ASTScopeKind::AbstractFunctionDecl.
/// An abstract function, for \c kind == ASTScopeKind::AbstractFunctionDecl
/// or \c kind == ASTScopeKind::AbstractFunctionBody.
AbstractFunctionDecl *abstractFunction;

/// An parameter for an abstract function (init/func/deinit).
Expand Down Expand Up @@ -314,8 +317,11 @@ class ASTScope {
this->genericParams.index = index;
}

ASTScope(const ASTScope *parent, AbstractFunctionDecl *abstractFunction)
: ASTScope(ASTScopeKind::AbstractFunctionDecl, parent) {
ASTScope(ASTScopeKind kind, const ASTScope *parent,
AbstractFunctionDecl *abstractFunction)
: ASTScope(kind, parent) {
assert(kind == ASTScopeKind::AbstractFunctionDecl ||
kind == ASTScopeKind::AbstractFunctionBody);
this->abstractFunction = abstractFunction;
}

Expand Down Expand Up @@ -513,9 +519,11 @@ class ASTScope {
}

/// Retrieve the abstract function declaration when
/// \c getKind() == ASTScopeKind::AbstractFunctionDecl;
/// \c getKind() == ASTScopeKind::AbstractFunctionDecl or
/// \c getKind() == ASTScopeKind::AbstractFunctionBody;
AbstractFunctionDecl *getAbstractFunctionDecl() const {
assert(getKind() == ASTScopeKind::AbstractFunctionDecl);
assert(getKind() == ASTScopeKind::AbstractFunctionDecl ||
getKind() == ASTScopeKind::AbstractFunctionBody);
return abstractFunction;
}

Expand Down
33 changes: 30 additions & 3 deletions lib/AST/ASTScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ void ASTScope::expand() const {
addChild(child);
break;

case ASTScopeKind::AbstractFunctionBody:
// Create a child for the actual body.
if (auto child = createIfNeeded(this, abstractFunction->getBody()))
addChild(child);
break;

case ASTScopeKind::PatternBinding: {
const auto &patternEntry =
patternBinding.decl->getPatternList()[patternBinding.entry];
Expand Down Expand Up @@ -588,6 +594,7 @@ static bool parentDirectDescendedFromLocalDeclaration(const ASTScope *parent,

case ASTScopeKind::SourceFile:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::PatternBinding:
case ASTScopeKind::PatternInitializer:
case ASTScopeKind::AfterPatternBinding:
Expand Down Expand Up @@ -633,6 +640,7 @@ static bool parentDirectDescendedFromAbstractStorageDecl(
case ASTScopeKind::SourceFile:
case ASTScopeKind::TypeOrExtensionBody:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::LocalDeclaration:
case ASTScopeKind::PatternBinding:
case ASTScopeKind::PatternInitializer:
Expand Down Expand Up @@ -668,6 +676,7 @@ static bool parentDirectDescendedFromAbstractFunctionDecl(
case ASTScopeKind::Preexpanded:
case ASTScopeKind::AbstractFunctionParams:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::GenericParams:
// Keep looking.
parent = parent->getParent();
Expand Down Expand Up @@ -741,7 +750,8 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
// an AbstractFunctionDecl scope, add it now.
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
if (!parentDirectDescendedFromAbstractFunctionDecl(parent, func)) {
return new (ctx) ASTScope(parent, func);
return new (ctx) ASTScope(ASTScopeKind::AbstractFunctionDecl, parent,
func);
}
}

Expand Down Expand Up @@ -879,9 +889,11 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
return afterParamScope;
}


// Function body, if present.
return createIfNeeded(parent, abstractFunction->getBody());
if (abstractFunction->hasBody())
return new (ctx) ASTScope(ASTScopeKind::AbstractFunctionBody, parent,
abstractFunction);
return nullptr;
}

case DeclKind::PatternBinding: {
Expand Down Expand Up @@ -1082,6 +1094,7 @@ bool ASTScope::isContinuationScope() const {
case ASTScopeKind::AbstractFunctionDecl:
case ASTScopeKind::AbstractFunctionParams:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::PatternBinding:
case ASTScopeKind::PatternInitializer:
case ASTScopeKind::Accessors:
Expand Down Expand Up @@ -1131,6 +1144,7 @@ void ASTScope::enumerateContinuationScopes(
case ASTScopeKind::Preexpanded:
case ASTScopeKind::SourceFile:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::PatternInitializer:
case ASTScopeKind::IfStmt:
case ASTScopeKind::RepeatWhileStmt:
Expand Down Expand Up @@ -1210,6 +1224,7 @@ ASTContext &ASTScope::getASTContext() const {
return genericParams.decl->getASTContext();

case ASTScopeKind::AbstractFunctionDecl:
case ASTScopeKind::AbstractFunctionBody:
return abstractFunction->getASTContext();

case ASTScopeKind::AbstractFunctionParams:
Expand Down Expand Up @@ -1328,6 +1343,9 @@ SourceRange ASTScope::getSourceRangeImpl() const {
case ASTScopeKind::DefaultArgument:
return parameter->getDefaultValue()->getSourceRange();

case ASTScopeKind::AbstractFunctionBody:
return abstractFunction->getBodySourceRange();

case ASTScopeKind::PatternBinding: {
const auto &patternEntry =
patternBinding.decl->getPatternList()[patternBinding.entry];
Expand Down Expand Up @@ -1596,6 +1614,7 @@ DeclContext *ASTScope::getDeclContext() const {
case ASTScopeKind::ForStmt:
case ASTScopeKind::ForStmtInitializer:
case ASTScopeKind::LocalDeclaration:
case ASTScopeKind::AbstractFunctionBody:
return nullptr;
}
}
Expand Down Expand Up @@ -1623,6 +1642,7 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
case ASTScopeKind::TypeOrExtensionBody:
case ASTScopeKind::AbstractFunctionDecl:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::PatternBinding:
case ASTScopeKind::PatternInitializer:
case ASTScopeKind::BraceStmt:
Expand Down Expand Up @@ -1794,6 +1814,13 @@ void ASTScope::print(llvm::raw_ostream &out, unsigned level,
printRange();
break;

case ASTScopeKind::AbstractFunctionBody:
printScopeKind("AbstractFunctionBody");
printAddress(abstractFunction);
out << " " << abstractFunction->getFullName();
printRange();
break;

case ASTScopeKind::PatternBinding:
printScopeKind("PatternBinding");
printAddress(patternBinding.decl);
Expand Down
18 changes: 17 additions & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ static DeclVisibilityKind getLocalDeclVisibilityKind(const ASTScope *scope) {
case ASTScopeKind::SourceFile:
case ASTScopeKind::TypeOrExtensionBody:
case ASTScopeKind::AbstractFunctionDecl:
case ASTScopeKind::AbstractFunctionBody:
case ASTScopeKind::DefaultArgument:
case ASTScopeKind::PatternBinding:
case ASTScopeKind::PatternInitializer:
Expand Down Expand Up @@ -477,6 +478,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,

// Walk scopes outward from the innermost scope until we find something.
bool lookupInNominalIsStatic = true;
ParamDecl *selfDecl = nullptr;
bool withinDefaultArgument = false;
for (auto currentScope = lookupScope; currentScope;
currentScope = currentScope->getParent()) {
Expand All @@ -490,6 +492,15 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
if (!Results.empty())
return;

// When we are in the body of a method, get the 'self' declaration.
if (currentScope->getKind() == ASTScopeKind::AbstractFunctionBody &&
currentScope->getAbstractFunctionDecl()->getDeclContext()
->isTypeContext()) {
selfDecl =
currentScope->getAbstractFunctionDecl()->getImplicitSelfDecl();
continue;
}

// If there is a declaration context associated with this scope, we might
// want to look in it.
if (auto dc = currentScope->getDeclContext()) {
Expand Down Expand Up @@ -590,8 +601,10 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,

SmallVector<ValueDecl *, 4> lookup;
dc->lookupQualified(lookupType, Name, options, TypeResolver, lookup);
ValueDecl *baseDecl = nominal;
if (selfDecl) baseDecl = selfDecl;
for (auto result : lookup) {
Results.push_back(UnqualifiedLookupResult(nominal, result));
Results.push_back(UnqualifiedLookupResult(baseDecl, result));
}

if (!Results.empty()) {
Expand All @@ -614,6 +627,9 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
return;
}
}

// Forget the 'self' declaration.
selfDecl = nullptr;
}
}
} else {
Expand Down
25 changes: 17 additions & 8 deletions test/NameBinding/scope_map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func localPatternsWithSharedType() {
// CHECK-EXPANDED-NEXT: -AbstractFunctionParams {{.*}} genericFunc0(t:u:i:) param 0:1 [22:34 - 23:1] expanded
// CHECK-EXPANDED: |-DefaultArgument {{.*}} [22:46 - 22:46] expanded
// CHECK-EXPANDED: `-AbstractFunctionParams {{.*}} genericFunc0(t:u:i:) param 0:2 [22:46 - 23:1] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} genericFunc0(t:u:i:) [22:50 - 23:1] expanded
// CHECK-EXPANDED-NEXT: -BraceStmt {{.*}} [22:50 - 23:1] expanded
// CHECK-EXPANDED-NEXT: -TypeOrExtensionBody {{.*}} 'ContainsGenerics0' [25:25 - 31:1] expanded
// CHECK-EXPANDED-NEXT: -AbstractFunctionDecl {{.*}} init(t:u:) [26:3 - 27:3] expanded
Expand All @@ -214,15 +215,18 @@ func localPatternsWithSharedType() {
// CHECK-EXPANDED-NEXT: -AbstractFunctionParams {{.*}} init(t:u:) param 0:0 [26:13 - 27:3] expanded
// CHECK-EXPANDED-NEXT: -AbstractFunctionParams {{.*}} init(t:u:) param 1:0 [26:17 - 27:3] expanded
// CHECK-EXPANDED-NEXT: -AbstractFunctionParams {{.*}} init(t:u:) param 1:1 [26:23 - 27:3] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} init(t:u:) [26:26 - 27:3] expanded
// CHECK-EXPANDED-NEXT: -BraceStmt {{.*}} [26:26 - 27:3] expanded
// CHECK-EXPANDED-NEXT: -AbstractFunctionDecl {{.*}} deinit
// CHECK-EXPANDED-NEXT: -AbstractFunctionParams {{.*}} deinit param 0:0 [29:3 - 30:3] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} deinit [29:10 - 30:3] expanded
// CHECK-EXPANDED-NEXT: -BraceStmt {{.*}} [29:10 - 30:3] expanded
// CHECK-EXPANDED-NEXT: -GenericParams {{.*}} param 0 [33:25 - 33:32] expanded
// CHECK-EXPANDED-NEXT: {{^[|`]}}-TypeOrExtensionBody {{.*}} '{{.*}}ArchStruct' [{{.*}}] expanded
// CHECK-EXPANDED-NEXT: {{^}}|-AbstractFunctionDecl {{.*}} functionBodies1(a:b:) [41:1 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} functionBodies1(a:b:) param 0:0 [41:25 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} functionBodies1(a:b:) param 0:1 [41:36 - 100:1] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} functionBodies1(a:b:) [41:39 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [41:39 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-PatternBinding {{.*}} entry 0 [42:7 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} |-PatternInitializer {{.*}} entry 0 [42:18 - 42:23] expanded
Expand Down Expand Up @@ -255,6 +259,7 @@ func localPatternsWithSharedType() {
// CHECK-EXPANDED-NEXT: {{^}} `-LocalDeclaration {{.*}} [57:3 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} |-AbstractFunctionDecl {{.*}} f(_:) [57:3 - 57:38] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} f(_:) param 0:0 [57:15 - 57:38] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} f(_:) [57:27 - 57:38] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [57:27 - 57:38] expanded
// CHECK-EXPANDED: {{^}} `-AfterPatternBinding {{.*}} entry 0 [58:16 - 100:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-LocalDeclaration {{.*}} [59:3 - 100:1] expanded
Expand Down Expand Up @@ -311,52 +316,56 @@ func localPatternsWithSharedType() {
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:0 [116:5 - 117:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:1 [116:5 - 117:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:2 [116:5 - 117:5] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} _ [116:9 - 117:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [116:9 - 117:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionDecl {{.*}} _ [118:5 - 120:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 0:0 [118:5 - 120:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:0 [118:5 - 120:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:1 [118:5 - 120:5] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} _ [118:9 - 120:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [118:9 - 120:5] expanded

// CHECK-EXPANDED: {{^}} `-Accessors {{.*}} scope_map.(file).StructContainsAbstractStorageDecls.computed@{{.*}}scope_map.swift:123:7 [123:21 - 129:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} |-AbstractFunctionDecl {{.*}} _ [124:5 - 126:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 0:0 [124:5 - 126:5] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} _ [124:9 - 126:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [124:9 - 126:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionDecl {{.*}} _ [127:5 - 128:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 0:0 [127:5 - 128:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:0 [127:5 - 128:5] expanded
// CHECK-EXPANDED-NEXT: `-AbstractFunctionBody {{.*}} _ [127:9 - 128:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [127:9 - 128:5] expanded

// CHECK-EXPANDED: {{^}}|-TypeOrExtensionBody {{.*}} 'ClassWithComputedProperties' [132:35 - 140:1] expanded
// CHECK-EXPANDED: {{^}} `-Accessors {{.*}} scope_map.(file).ClassWithComputedProperties.willSetProperty@{{.*}}scope_map.swift:133:7 [133:32 - 135:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionDecl {{.*}} _ [134:5 - 134:15] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 0:0 [134:5 - 134:15] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:0 [134:5 - 134:15] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [134:13 - 134:15] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [134:13 - 134:15] expanded
// CHECK-EXPANDED: {{^}} `-Accessors {{.*}} scope_map.(file).ClassWithComputedProperties.didSetProperty@{{.*}}scope_map.swift:137:7 [137:31 - 139:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionDecl {{.*}} _ [138:5 - 138:14] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 0:0 [138:5 - 138:14] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 1:0 [138:5 - 138:14] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [138:12 - 138:14] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [138:12 - 138:14] expanded

// CHECK-EXPANDED: {{^}} `-AbstractFunctionParams {{.*}} funcWithComputedProperties(i:) param 0:0 [142:36 - 155:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [142:41 - 155:1] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [142:41 - 155:1] expanded
// CHECK-EXPANDED: {{^}} |-Accessors {{.*}} scope_map.(file).func decl.computed@{{.*}}scope_map.swift:143:7 [143:21 - 149:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} |-AbstractFunctionDecl {{.*}} _ [144:5 - 145:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionParams {{.*}} _ param 0:0 [144:5 - 145:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [144:9 - 145:5] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [144:9 - 145:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-AbstractFunctionDecl {{.*}} _ [146:5 - 148:5] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [146:9 - 148:5] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [146:9 - 148:5] expanded
// CHECK-EXPANDED: {{^}} `-AfterPatternBinding {{.*}} entry 0 [149:3 - 155:1] expanded
// CHECK-EXPANDED: {{^}} `-AfterPatternBinding {{.*}} entry 1 [149:36 - 155:1] expanded
// CHECK-EXPANDED: {{^}} `-AfterPatternBinding {{.*}} entry 2 [150:21 - 155:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-LocalDeclaration {{.*}} [150:25 - 155:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} |-AbstractFunctionDecl {{.*}} _ [150:25 - 152:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [150:25 - 152:3] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [150:25 - 152:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [154:6 - 154:8] expanded

// CHECK-EXPANDED: |-AbstractFunctionDecl {{.*}} closures() [157:1 - 162:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [157:17 - 162:1] expanded
// CHECK-EXPANDED: {{^}} `-BraceStmt {{.*}} [157:17 - 162:1] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-Preexpanded {{.*}} [158:10 - 161:19] expanded
// CHECK-EXPANDED-NEXT: {{^}} |-Closure {{.*}} [158:10 - 160:3] expanded
// CHECK-EXPANDED-NEXT: {{^}} `-BraceStmt {{.*}} [158:10 - 160:3] expanded
Expand Down Expand Up @@ -388,7 +397,7 @@ func localPatternsWithSharedType() {
// CHECK-EXPANDED-NEXT: `-AbstractFunctionParams {{.*}} _ param 1:1 [183:39 - 183:39] expanded

// CHECK-EXPANDED: `-AbstractFunctionDecl {{.*}} localPatternsWithSharedType() [186:1 - 188:1] expanded
// CHECK-EXPANDED-NEXT: `-BraceStmt {{.*}} [186:36 - 188:1] expanded
// CHECK-EXPANDED: `-BraceStmt {{.*}} [186:36 - 188:1] expanded
// CHECK-EXPANDED-NEXT: `-PatternBinding {{.*}} entry 0 [187:7 - 188:1] expanded
// CHECK-EXPANDED-NEXT: `-AfterPatternBinding {{.*}} entry 0 [187:7 - 188:1] expanded
// CHECK-EXPANDED-NEXT: `-PatternBinding {{.*}} entry 1 [187:10 - 188:1] expanded
Expand Down
8 changes: 8 additions & 0 deletions test/NameBinding/scope_map_lookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ func functionParamScopes(x: Int, y: Int = x) -> Int {
return x + y
}

// Name binding in instance methods.
class C1 {
var x = 0

var hashValue: Int {
return x
}
}