From 4c38f89462b37563b3d1b9d156e53772f9422311 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 4 Apr 2016 13:16:10 -0700 Subject: [PATCH] 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. --- lib/Sema/CodeSynthesis.cpp | 2 ++ test/decl/var/Inputs/lazy_properties_multi_file_2.swift | 4 ++++ test/decl/var/lazy_properties_multi_file.swift | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 test/decl/var/Inputs/lazy_properties_multi_file_2.swift create mode 100644 test/decl/var/lazy_properties_multi_file.swift diff --git a/lib/Sema/CodeSynthesis.cpp b/lib/Sema/CodeSynthesis.cpp index 0772b3bd4f418..cbac86712841c 100644 --- a/lib/Sema/CodeSynthesis.cpp +++ b/lib/Sema/CodeSynthesis.cpp @@ -1184,10 +1184,12 @@ void TypeChecker::completeLazyVarImplementation(VarDecl *VD) { NameBuf += ".storage"; auto StorageName = Context.getIdentifier(NameBuf); auto StorageTy = OptionalType::get(VD->getType()); + auto StorageInterfaceTy = OptionalType::get(VD->getInterfaceType()); auto *Storage = new (Context) VarDecl(/*isStatic*/false, /*isLet*/false, VD->getLoc(), StorageName, StorageTy, VD->getDeclContext()); + Storage->setInterfaceType(StorageInterfaceTy); Storage->setUserAccessible(false); addMemberToContextIfNeeded(Storage, VD->getDeclContext(), VD); diff --git a/test/decl/var/Inputs/lazy_properties_multi_file_2.swift b/test/decl/var/Inputs/lazy_properties_multi_file_2.swift new file mode 100644 index 0000000000000..5d0aae90f1e3f --- /dev/null +++ b/test/decl/var/Inputs/lazy_properties_multi_file_2.swift @@ -0,0 +1,4 @@ +struct MyGenericStruct { + lazy var prop2 = [AnotherGenericStruct]() +} +struct AnotherGenericStruct { } diff --git a/test/decl/var/lazy_properties_multi_file.swift b/test/decl/var/lazy_properties_multi_file.swift new file mode 100644 index 0000000000000..95f9b8131ea43 --- /dev/null +++ b/test/decl/var/lazy_properties_multi_file.swift @@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// 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 + +class MyClass { + var myProperty = MyGenericStruct() +}