[ClangImporter] Forward generic parameters to renamed typealias

While trying to import declaration which requires renaming forward
generic parameters (if any) to newly created typealias.
This commit is contained in:
Pavel Yaskevich
2018-06-13 12:51:12 -07:00
parent 094949a461
commit 1f3714f264
2 changed files with 11 additions and 15 deletions

View File

@@ -5188,18 +5188,6 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
if (!typeDecl)
return nullptr;
// Deliberately use an UnboundGenericType to avoid having to translate over
// generic parameters.
Type underlyingType;
if (auto *underlyingAlias = dyn_cast<TypeAliasDecl>(typeDecl)) {
if (underlyingAlias->isGeneric())
underlyingType = underlyingAlias->getUnboundGenericType();
else
underlyingType = Impl.getSugaredTypeReference(underlyingAlias);
} else {
underlyingType = cast<NominalTypeDecl>(typeDecl)->getDeclaredType();
}
auto dc = Impl.importDeclContextOf(decl,
compatibilityName.getEffectiveContext());
if (!dc)
@@ -5210,7 +5198,15 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
decl, AccessLevel::Public, Impl.importSourceLoc(decl->getLocStart()),
SourceLoc(), compatibilityName.getDeclName().getBaseIdentifier(),
Impl.importSourceLoc(decl->getLocation()), /*generic params*/nullptr, dc);
alias->setUnderlyingType(underlyingType);
auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl);
if (GTD && !isa<ProtocolDecl>(GTD)) {
alias->setGenericEnvironment(GTD->getGenericEnvironment());
if (GTD->isGeneric())
alias->setGenericParams(GTD->getGenericParams()->clone(alias));
}
alias->setUnderlyingType(Impl.getSugaredTypeReference(typeDecl));
// Record that this is the official version of this declaration.
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = alias;

View File

@@ -34,9 +34,9 @@ func testRenamedGeneric() {
class SwiftClass {}
// CHECK-DIAGS-3:[[@LINE+1]]:{{[0-9]+}}: error: 'RenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
// CHECK-DIAGS-3:[[@LINE+1]]:{{[0-9]+}}: error: 'OldRenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
let _: OldRenamedGeneric<SwiftClass> = RenamedGeneric<SwiftClass>()
// CHECK-DIAGS-4:[[@LINE-1]]:{{[0-9]+}}: error: 'RenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
// CHECK-DIAGS-4:[[@LINE-1]]:{{[0-9]+}}: error: 'OldRenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
// CHECK-DIAGS-3:[[@LINE+1]]:{{[0-9]+}}: error: 'RenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
let _: RenamedGeneric<SwiftClass> = OldRenamedGeneric<SwiftClass>()