mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SILGen: Fix the logic of dynamic replacements for class constructors
To correctly call designated super class initializers the designated intializer (and not the allocator) is dynamically replaceable. Convenience allocators are dynamically replaceable as before.
This commit is contained in:
@@ -1019,12 +1019,35 @@ unsigned SILDeclRef::getParameterListCount() const {
|
||||
}
|
||||
}
|
||||
|
||||
static bool isDesignatedConstructorForClass(ValueDecl *decl) {
|
||||
if (auto *ctor = dyn_cast_or_null<ConstructorDecl>(decl))
|
||||
if (ctor->getDeclContext()->getSelfClassDecl())
|
||||
return ctor->isDesignatedInit();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SILDeclRef::canBeDynamicReplacement() const {
|
||||
if (kind == SILDeclRef::Kind::Destroyer)
|
||||
return false;
|
||||
if (kind == SILDeclRef::Kind::Initializer)
|
||||
return isDesignatedConstructorForClass(getDecl());
|
||||
if (kind == SILDeclRef::Kind::Allocator)
|
||||
return !isDesignatedConstructorForClass(getDecl());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SILDeclRef::isDynamicallyReplaceable() const {
|
||||
if (isStoredPropertyInitializer())
|
||||
return false;
|
||||
|
||||
// Class allocators are not dynamic replaceable.
|
||||
if (kind == SILDeclRef::Kind::Allocator &&
|
||||
isDesignatedConstructorForClass(getDecl()))
|
||||
return false;
|
||||
|
||||
if (kind == SILDeclRef::Kind::Destroyer ||
|
||||
kind == SILDeclRef::Kind::Initializer ||
|
||||
(kind == SILDeclRef::Kind::Initializer &&
|
||||
!isDesignatedConstructorForClass(getDecl())) ||
|
||||
kind == SILDeclRef::Kind::GlobalAccessor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user