Skip to content

Commit 88847f1

Browse files
committed
Sema: Set the interface type of lazy properties during validation.
Otherwise, we end up treating the contextual type as the interface type in situations where the lazy property is seen from other files. Fixes SR-837.
1 parent 2d8d7ad commit 88847f1

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,10 +1581,12 @@ void TypeChecker::completeLazyVarImplementation(VarDecl *VD) {
15811581
NameBuf += ".storage";
15821582
auto StorageName = Context.getIdentifier(NameBuf);
15831583
auto StorageTy = OptionalType::get(VD->getType());
1584+
auto StorageInterfaceTy = OptionalType::get(VD->getInterfaceType());
15841585

15851586
auto *Storage = new (Context) VarDecl(/*isStatic*/false, /*isLet*/false,
15861587
VD->getLoc(), StorageName, StorageTy,
15871588
VD->getDeclContext());
1589+
Storage->setInterfaceType(StorageInterfaceTy);
15881590
Storage->setUserAccessible(false);
15891591
addMemberToContextIfNeeded(Storage, VD->getDeclContext(), VD);
15901592

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct MyGenericStruct<T> {
2+
lazy var prop2 = [AnotherGenericStruct<T>]()
3+
}
4+
struct AnotherGenericStruct<T> { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: %target-swift-frontend %s -verify -O -primary-file %s %S/Inputs/lazy_properties_multi_file_2.swift -c -o %t/lazy_properties_multi_file.o
4+
5+
class MyClass {
6+
var myProperty = MyGenericStruct<Int>()
7+
}

0 commit comments

Comments
 (0)