Skip to content

Commit 28bede4

Browse files
authored
Merge pull request #38046 from xymus/typo-ioi
[Serialization] Recover from deserialization failures in `ModuleFile::lookupClassMembers`
2 parents a401d3d + 4f0c57a commit 28bede4

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,13 @@ void ModuleFile::lookupClassMembers(ImportPath::Access accessPath,
794794
if (!accessPath.empty()) {
795795
for (const auto &list : Core->ClassMembersForDynamicLookup->data()) {
796796
for (auto item : list) {
797-
auto vd = cast<ValueDecl>(getDecl(item.second));
797+
auto decl = getDeclChecked(item.second);
798+
if (!decl) {
799+
llvm::consumeError(decl.takeError());
800+
continue;
801+
}
802+
803+
auto vd = cast<ValueDecl>(decl.get());
798804
auto dc = vd->getDeclContext();
799805
while (!dc->getParent()->isModuleScopeContext())
800806
dc = dc->getParent();
@@ -808,10 +814,17 @@ void ModuleFile::lookupClassMembers(ImportPath::Access accessPath,
808814
}
809815

810816
for (const auto &list : Core->ClassMembersForDynamicLookup->data()) {
811-
for (auto item : list)
812-
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)),
817+
for (auto item : list) {
818+
auto decl = getDeclChecked(item.second);
819+
if (!decl) {
820+
llvm::consumeError(decl.takeError());
821+
continue;
822+
}
823+
824+
consumer.foundDecl(cast<ValueDecl>(decl.get()),
813825
DeclVisibilityKind::DynamicLookup,
814826
DynamicLookupInfo::AnyObject);
827+
}
815828
}
816829
}
817830

test/Serialization/Recovery/implementation-only-missing.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
//// The client app should build OK without the private module. Removing the
1313
//// private module is superfluous but makes sure that it's not somehow loaded.
1414
// RUN: rm %t/private_lib.swiftmodule
15-
// RUN: %target-swift-frontend -typecheck -DCLIENT_APP -primary-file %s -I %t -index-system-modules -index-store-path %t
16-
// RUN: %target-swift-frontend -emit-sil -DCLIENT_APP -primary-file %s -I %t -module-name client
15+
// RUN: %target-swift-frontend -typecheck -DCLIENT_APP %s -I %t -index-system-modules -index-store-path %t
16+
// RUN: %target-swift-frontend -typecheck -DCLIENT_APP %s -I %t -D FAIL_TYPECHECK -verify
17+
// RUN: %target-swift-frontend -emit-sil -DCLIENT_APP %s -I %t -module-name client
1718

1819
//// Printing the public module should not crash when checking for overrides of
1920
//// methods from the private module.
@@ -46,6 +47,8 @@ public protocol HiddenProtocolWithOverride {
4647
func hiddenOverride()
4748
}
4849

50+
public class HiddenClass {}
51+
4952
#elseif PUBLIC_LIB
5053

5154
@_implementationOnly import private_lib
@@ -91,6 +94,10 @@ public struct PublicStructConformsToHiddenProtocol: RefinesHiddenProtocol {
9194
public init() { }
9295
}
9396

97+
public class SomeClass {
98+
func funcUsingIoiType(_ a: HiddenClass) {}
99+
}
100+
94101
#elseif CLIENT_APP
95102

96103
import public_lib
@@ -101,4 +108,12 @@ print(s.nonWrappedVar)
101108
var p = PublicStructConformsToHiddenProtocol()
102109
print(p)
103110

111+
#if FAIL_TYPECHECK
112+
// Access to a missing member on an AnyObject triggers a typo correction
113+
// that looks at *all* class members. rdar://79427805
114+
class ClassUnrelatedToSomeClass {}
115+
var something = ClassUnrelatedToSomeClass() as AnyObject
116+
something.triggerTypoCorrection = 123 // expected-error {{value of type 'AnyObject' has no member 'triggerTypoCorrection'}}
117+
#endif
118+
104119
#endif

0 commit comments

Comments
 (0)