Skip to content

Commit 0f02901

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. (cherry picked from commit 1f3714f)
1 parent c68db29 commit 0f02901

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
@@ -5183,18 +5183,6 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
51835183
if (!typeDecl)
51845184
return nullptr;
51855185

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

52105206
// Record that this is the official version of this declaration.
52115207
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)