Skip to content

Commit 275278e

Browse files
authored
Merge pull request #37490 from ahoppen/pr-5.4/rdar-78035645
[5.4][Deserialization] Fix error when typealias required by protocol refers to type in @_implementationOnly module
2 parents 7213dab + 3722969 commit 275278e

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
@@ -6197,8 +6197,26 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
61976197
// FIXME: We don't actually want to allocate an archetype here; we just
61986198
// want to get an access path within the protocol.
61996199
auto first = cast<AssociatedTypeDecl>(getDecl(*rawIDIter++));
6200-
auto second = getType(*rawIDIter++);
6201-
auto third = cast_or_null<TypeDecl>(getDecl(*rawIDIter++));
6200+
auto secondOrError = getTypeChecked(*rawIDIter++);
6201+
Type second;
6202+
if (secondOrError) {
6203+
second = *secondOrError;
6204+
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
6205+
second = ErrorType::get(getContext());
6206+
consumeError(secondOrError.takeError());
6207+
} else {
6208+
fatal(secondOrError.takeError());
6209+
}
6210+
auto thirdOrError = getDeclChecked(*rawIDIter++);
6211+
TypeDecl *third;
6212+
if (thirdOrError) {
6213+
third = cast_or_null<TypeDecl>(*thirdOrError);
6214+
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
6215+
third = nullptr;
6216+
consumeError(thirdOrError.takeError());
6217+
} else {
6218+
fatal(thirdOrError.takeError());
6219+
}
62026220
if (third &&
62036221
isa<TypeAliasDecl>(third) &&
62046222
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)