Skip to content

Commit

Permalink
Serialization: When deserializing a typealias, build its generic sign…
Browse files Browse the repository at this point in the history
…ature

We were forgetting to do this, triggering crashes when using a
generic typealias from another module.

Fixes <https://bugs.swift.org/browse/SR-1889>.
  • Loading branch information
slavapestov committed Jun 24, 2016
1 parent 40ba708 commit c06fd1a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/Serialization/Deserialization.cpp
Expand Up @@ -2163,6 +2163,21 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
genericParams, DC);
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();

if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/Serialization.cpp
Expand Up @@ -2191,6 +2191,7 @@ void Serializer::writeDecl(const Decl *D) {
typeAlias->isImplicit(),
rawAccessLevel);
writeGenericParams(typeAlias->getGenericParams(), DeclTypeAbbrCodes);
writeRequirements(typeAlias->getGenericRequirements());
break;
}

Expand Down
9 changes: 9 additions & 0 deletions test/multifile/typealias/two-modules/library.swift
@@ -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 changes: 13 additions & 0 deletions test/multifile/typealias/two-modules/main.swift
@@ -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 }

0 comments on commit c06fd1a

Please sign in to comment.