Skip to content

[Deserialization] Fix error when typealias required by protocol refers to type in @_implementationOnly module #37011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6390,8 +6390,26 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
// FIXME: We don't actually want to allocate an archetype here; we just
// want to get an access path within the protocol.
auto first = cast<AssociatedTypeDecl>(getDecl(*rawIDIter++));
auto second = getType(*rawIDIter++);
auto third = cast_or_null<TypeDecl>(getDecl(*rawIDIter++));
auto secondOrError = getTypeChecked(*rawIDIter++);
Type second;
if (secondOrError) {
second = *secondOrError;
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
second = ErrorType::get(getContext());
consumeError(secondOrError.takeError());
} else {
fatal(secondOrError.takeError());
}
auto thirdOrError = getDeclChecked(*rawIDIter++);
TypeDecl *third;
if (thirdOrError) {
third = cast_or_null<TypeDecl>(*thirdOrError);
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
third = nullptr;
consumeError(thirdOrError.takeError());
} else {
fatal(thirdOrError.takeError());
}
if (third &&
isa<TypeAliasDecl>(third) &&
third->getModuleContext() != getAssociatedModule() &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module public_lib [system] {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %empty-directory(%t)

//// Build the private module and the public module normally.
//// Force the public module to be system with an underlying Clang module.
// RUN: %target-swift-frontend -emit-module -DPRIVATE_LIB %s -module-name private_lib -emit-module-path %t/private_lib.swiftmodule
// 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

//// Printing the public module should not crash when reading the HiddenStruct typealias in `M`.
// RUN: %target-swift-ide-test -print-module -module-to-print=public_lib -source-filename=x -skip-overrides -I %t

#if PRIVATE_LIB

public struct HiddenStruct {
public init() {}
}

#elseif PUBLIC_LIB

@_implementationOnly import private_lib

protocol SomeProtocol {
associatedtype Value
static var defaultValue: Value { get }
}
public struct M: SomeProtocol {
typealias Value = HiddenStruct
static let defaultValue = HiddenStruct()
}
#endif