Skip to content

Commit aa78216

Browse files
authored
Merge pull request #37011 from ahoppen/pr/deserialization-error
[Deserialization] Fix error when typealias required by protocol refers to type in @_implementationOnly module
2 parents 727c11d + ab2fdbb commit aa78216

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6390,8 +6390,26 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
63906390
// FIXME: We don't actually want to allocate an archetype here; we just
63916391
// want to get an access path within the protocol.
63926392
auto first = cast<AssociatedTypeDecl>(getDecl(*rawIDIter++));
6393-
auto second = getType(*rawIDIter++);
6394-
auto third = cast_or_null<TypeDecl>(getDecl(*rawIDIter++));
6393+
auto secondOrError = getTypeChecked(*rawIDIter++);
6394+
Type second;
6395+
if (secondOrError) {
6396+
second = *secondOrError;
6397+
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
6398+
second = ErrorType::get(getContext());
6399+
consumeError(secondOrError.takeError());
6400+
} else {
6401+
fatal(secondOrError.takeError());
6402+
}
6403+
auto thirdOrError = getDeclChecked(*rawIDIter++);
6404+
TypeDecl *third;
6405+
if (thirdOrError) {
6406+
third = cast_or_null<TypeDecl>(*thirdOrError);
6407+
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
6408+
third = nullptr;
6409+
consumeError(thirdOrError.takeError());
6410+
} else {
6411+
fatal(thirdOrError.takeError());
6412+
}
63956413
if (third &&
63966414
isa<TypeAliasDecl>(third) &&
63976415
third->getModuleContext() != getAssociatedModule() &&
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module public_lib [system] {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
3+
//// Build the private module and the public module normally.
4+
//// Force the public module to be system with an underlying Clang module.
5+
// RUN: %target-swift-frontend -emit-module -DPRIVATE_LIB %s -module-name private_lib -emit-module-path %t/private_lib.swiftmodule
6+
// RUN: %target-swift-frontend -emit-module -DPUBLIC_LIB %s -module-name public_lib -emit-module-path %t/public_lib.swiftmodule -I %t -I %S/Inputs/protocol-requirement-in-implementation-only -import-underlying-module
7+
8+
//// Printing the public module should not crash when reading the HiddenStruct typealias in `M`.
9+
// RUN: %target-swift-ide-test -print-module -module-to-print=public_lib -source-filename=x -skip-overrides -I %t
10+
11+
#if PRIVATE_LIB
12+
13+
public struct HiddenStruct {
14+
public init() {}
15+
}
16+
17+
#elseif PUBLIC_LIB
18+
19+
@_implementationOnly import private_lib
20+
21+
protocol SomeProtocol {
22+
associatedtype Value
23+
static var defaultValue: Value { get }
24+
}
25+
public struct M: SomeProtocol {
26+
typealias Value = HiddenStruct
27+
static let defaultValue = HiddenStruct()
28+
}
29+
#endif

0 commit comments

Comments
 (0)