Native: apply ObjCExport virtual adapters from interfaces of supers

Previously they were skipped, and this was an incorrect optimization:
even if super class implements the interface too, this doesn't mean
that virtual adapters provided by that interface are inherited
by non-exported subclass that needs them;
for example, this doesn't happen when the super class is exported
(i.e. Obj-C class is not created at runtime).

Remove incorrect optimization instead of making it more sophisticated,
because it is useless anyway.

^KT-46431 Fixed
This commit is contained in:
Svyatoslav Scherbina
2021-06-11 15:35:25 +03:00
committed by Space
parent b7fbe09ef4
commit 5d5628f56e
5 changed files with 82 additions and 4 deletions
@@ -731,6 +731,24 @@ __attribute__((swift_name("Kt43599Kt")))
@property (class, readonly) NSString *topLevelLateinitProperty __attribute__((swift_name("topLevelLateinitProperty")));
@end;
__attribute__((swift_name("Host")))
@protocol KtHost
@required
@property (readonly) NSString *test __attribute__((swift_name("test")));
@end;
__attribute__((swift_name("AbstractHost")))
@interface KtAbstractHost : KtBase <KtHost>
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Kt46431Kt")))
@interface KtKt46431Kt : KtBase
+ (id<KtHost>)createAbstractHost __attribute__((swift_name("createAbstractHost()")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("KT43780TestObject")))
@interface KtKT43780TestObject : KtBase
@@ -673,6 +673,24 @@ __attribute__((swift_name("Kt43599Kt")))
@property (class, readonly) NSString *topLevelLateinitProperty __attribute__((swift_name("topLevelLateinitProperty")));
@end;
__attribute__((swift_name("Host")))
@protocol KtHost
@required
@property (readonly) NSString *test __attribute__((swift_name("test")));
@end;
__attribute__((swift_name("AbstractHost")))
@interface KtAbstractHost : KtBase <KtHost>
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Kt46431Kt")))
@interface KtKt46431Kt : KtBase
+ (id<KtHost>)createAbstractHost __attribute__((swift_name("createAbstractHost()")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("KT43780TestObject")))
@interface KtKT43780TestObject : KtBase
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package kt43599
// Based on https://youtrack.jetbrains.com/issue/KT-46431
interface Host {
val test: String
}
abstract class AbstractHost : Host
fun createAbstractHost(): Host {
return object : AbstractHost() {
override val test: String
get() = "1234"
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import Kt
// Based on https://youtrack.jetbrains.com/issue/KT-46431.
private func test1() throws {
try assertEquals(actual: Kt46431Kt.createAbstractHost().test, expected: "1234")
}
class Kt46431Tests : SimpleTestProvider {
override init() {
super.init()
test("Test1", test1)
}
}
@@ -1027,10 +1027,12 @@ static Class createClass(const TypeInfo* typeInfo, Class superClass) {
for (int i = 0; i < typeInfo->implementedInterfacesCount_; ++i) {
const TypeInfo* interface = typeInfo->implementedInterfaces_[i];
if (superImplementedInterfaces.find(interface) == superImplementedInterfaces.end()) {
const ObjCTypeAdapter* typeAdapter = getTypeAdapter(interface);
if (typeAdapter != nullptr) {
addVirtualAdapters(result, typeAdapter);
const ObjCTypeAdapter* typeAdapter = getTypeAdapter(interface);
if (typeAdapter != nullptr) {
// Note: we could avoid adding virtual adapters if inherited from super type,
// but what's the point?
addVirtualAdapters(result, typeAdapter);
if (superImplementedInterfaces.find(interface) == superImplementedInterfaces.end()) {
addProtocolForAdapter(result, typeAdapter);
}
}