Skip to content

Commit 433b7f2

Browse files
committed
Sema: Fix bug with name lookup from initializers
1 parent 632fdf5 commit 433b7f2

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818
#include "TypeChecker.h"
19+
#include "swift/AST/Initializer.h"
1920
#include "swift/AST/NameLookup.h"
2021
#include "swift/AST/ProtocolConformance.h"
2122
#include "swift/Basic/TopCollection.h"
@@ -192,7 +193,10 @@ LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclName name,
192193
auto baseDC = baseParam->getDeclContext();
193194
if (isa<AbstractFunctionDecl>(baseDC))
194195
baseDC = baseDC->getParent();
196+
if (isa<PatternBindingInitializer>(baseDC))
197+
baseDC = baseDC->getParent();
195198
foundInType = baseDC->getDeclaredTypeInContext();
199+
assert(foundInType && "bogus base declaration?");
196200
} else {
197201
auto baseNominal = cast<NominalTypeDecl>(found.getBaseDecl());
198202
for (auto currentDC = dc; currentDC; currentDC = currentDC->getParent()) {

test/decl/var/lazy_properties.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,6 @@ class ReferenceSelfInLazyProperty : BaseClass {
159159

160160
var i = 42
161161
func f() -> Int { return 0 }
162+
163+
lazy var refBaseClassProp = baseInstanceProp
162164
}

validation-test/compiler_crashers/28763-swift-typebase-getcanonicaltype.swift renamed to validation-test/compiler_crashers_fixed/28763-swift-typebase-getcanonicaltype.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
protocol P{func a}extension P{lazy var f=a

0 commit comments

Comments
 (0)