mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Serialization: When deserializing a typealias, build its generic signature
We were forgetting to do this, triggering crashes when using a generic typealias from another module. Fixes <https://bugs.swift.org/browse/SR-1889>.
This commit is contained in:
@@ -2163,6 +2163,21 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
|||||||
genericParams, DC);
|
genericParams, DC);
|
||||||
declOrOffset = alias;
|
declOrOffset = alias;
|
||||||
|
|
||||||
|
if (genericParams) {
|
||||||
|
SmallVector<GenericTypeParamType *, 4> paramTypes;
|
||||||
|
for (auto &genericParam : *genericParams) {
|
||||||
|
paramTypes.push_back(genericParam->getDeclaredType()
|
||||||
|
->castTo<GenericTypeParamType>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the generic requirements.
|
||||||
|
SmallVector<Requirement, 4> requirements;
|
||||||
|
readGenericRequirements(requirements);
|
||||||
|
|
||||||
|
auto sig = GenericSignature::get(paramTypes, requirements);
|
||||||
|
alias->setGenericSignature(sig);
|
||||||
|
}
|
||||||
|
|
||||||
alias->computeType();
|
alias->computeType();
|
||||||
|
|
||||||
if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
|
if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
|
||||||
|
|||||||
@@ -2191,6 +2191,7 @@ void Serializer::writeDecl(const Decl *D) {
|
|||||||
typeAlias->isImplicit(),
|
typeAlias->isImplicit(),
|
||||||
rawAccessLevel);
|
rawAccessLevel);
|
||||||
writeGenericParams(typeAlias->getGenericParams(), DeclTypeAbbrCodes);
|
writeGenericParams(typeAlias->getGenericParams(), DeclTypeAbbrCodes);
|
||||||
|
writeRequirements(typeAlias->getGenericRequirements());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
test/multifile/typealias/two-modules/library.swift
Normal file
9
test/multifile/typealias/two-modules/library.swift
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// RUN: true
|
||||||
|
|
||||||
|
public enum Result<T, U>
|
||||||
|
{
|
||||||
|
case success(T)
|
||||||
|
case failure(U)
|
||||||
|
}
|
||||||
|
|
||||||
|
public typealias GenericResult<T> = Result<T, ErrorProtocol>
|
||||||
13
test/multifile/typealias/two-modules/main.swift
Normal file
13
test/multifile/typealias/two-modules/main.swift
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// RUN: rm -rf %t && mkdir %t
|
||||||
|
|
||||||
|
// RUN: mkdir %t/linker
|
||||||
|
// RUN: %target-build-swift -emit-module -c %S/library.swift -o %t/linker/library.o
|
||||||
|
// RUN: %target-build-swift -emit-library -c %S/library.swift -o %t/linker/library.o
|
||||||
|
// RUN: %target-build-swift %S/main.swift %t/linker/library.o -I %t/linker/ -L %t/linker/ -o %t/linker/main
|
||||||
|
|
||||||
|
// REQUIRES: executable_test
|
||||||
|
|
||||||
|
import library
|
||||||
|
|
||||||
|
func testFunction<T>(withCompletion completion: (Result<T, ErrorProtocol>) -> Void) { }
|
||||||
|
testFunction { (result: GenericResult<Int>) in }
|
||||||
Reference in New Issue
Block a user