mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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;
|
||||
|
||||
@@ -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>()
|
||||
|
||||
Reference in New Issue
Block a user