Skip to content

Commit 1f3714f

Browse files
committed
[ClangImporter] Forward generic parameters to renamed typealias
While trying to import declaration which requires renaming forward generic parameters (if any) to newly created typealias.
1 parent 094949a commit 1f3714f

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,18 +5188,6 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
51885188
if (!typeDecl)
51895189
return nullptr;
51905190

5191-
// Deliberately use an UnboundGenericType to avoid having to translate over
5192-
// generic parameters.
5193-
Type underlyingType;
5194-
if (auto *underlyingAlias = dyn_cast<TypeAliasDecl>(typeDecl)) {
5195-
if (underlyingAlias->isGeneric())
5196-
underlyingType = underlyingAlias->getUnboundGenericType();
5197-
else
5198-
underlyingType = Impl.getSugaredTypeReference(underlyingAlias);
5199-
} else {
5200-
underlyingType = cast<NominalTypeDecl>(typeDecl)->getDeclaredType();
5201-
}
5202-
52035191
auto dc = Impl.importDeclContextOf(decl,
52045192
compatibilityName.getEffectiveContext());
52055193
if (!dc)
@@ -5210,7 +5198,15 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
52105198
decl, AccessLevel::Public, Impl.importSourceLoc(decl->getLocStart()),
52115199
SourceLoc(), compatibilityName.getDeclName().getBaseIdentifier(),
52125200
Impl.importSourceLoc(decl->getLocation()), /*generic params*/nullptr, dc);
5213-
alias->setUnderlyingType(underlyingType);
5201+
5202+
auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl);
5203+
if (GTD && !isa<ProtocolDecl>(GTD)) {
5204+
alias->setGenericEnvironment(GTD->getGenericEnvironment());
5205+
if (GTD->isGeneric())
5206+
alias->setGenericParams(GTD->getGenericParams()->clone(alias));
5207+
}
5208+
5209+
alias->setUnderlyingType(Impl.getSugaredTypeReference(typeDecl));
52145210

52155211
// Record that this is the official version of this declaration.
52165212
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = alias;

test/APINotes/versioned-objc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func testRenamedGeneric() {
3434

3535
class SwiftClass {}
3636

37-
// CHECK-DIAGS-3:[[@LINE+1]]:{{[0-9]+}}: error: 'RenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
37+
// CHECK-DIAGS-3:[[@LINE+1]]:{{[0-9]+}}: error: 'OldRenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
3838
let _: OldRenamedGeneric<SwiftClass> = RenamedGeneric<SwiftClass>()
39-
// CHECK-DIAGS-4:[[@LINE-1]]:{{[0-9]+}}: error: 'RenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
39+
// CHECK-DIAGS-4:[[@LINE-1]]:{{[0-9]+}}: error: 'OldRenamedGeneric' requires that 'SwiftClass' inherit from 'Base'
4040

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

0 commit comments

Comments
 (0)