Avoid duplicated selectors when Kotlin class inherits from muliple ba… (#4145)
Issue: RuntimeAssert in AddMethods (ObjCInterop.mm) when kotlin class overrides the same selector from multiple bases, e.g. from the base objc class and a protocol(s).
This commit is contained in:
+4
-2
@@ -864,12 +864,14 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi
|
||||
override fun visitClass(declaration: IrClass): IrStatement {
|
||||
super.visitClass(declaration)
|
||||
if (declaration.isKotlinObjCClass()) {
|
||||
val uniq = mutableSetOf<String>() // remove duplicates [KT-38234]
|
||||
val imps = declaration.simpleFunctions().filter { it.isReal }.flatMap { function ->
|
||||
function.overriddenSymbols.mapNotNull {
|
||||
val info = it.owner.getExternalObjCMethodInfo()
|
||||
if (info == null) {
|
||||
val selector = it.owner.getExternalObjCMethodInfo()?.selector
|
||||
if (selector == null || selector in uniq) {
|
||||
null
|
||||
} else {
|
||||
uniq += selector
|
||||
generateWithStubs(it.owner) {
|
||||
generateCFunctionAndFakeKotlinExternalFunction(
|
||||
function,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
@protocol KT38234_P1
|
||||
-(int)foo;
|
||||
@end;
|
||||
|
||||
@interface KT38234_Base : NSObject <KT38234_P1>
|
||||
-(int)callFoo;
|
||||
@end;
|
||||
@@ -0,0 +1,10 @@
|
||||
import kotlin.test.*
|
||||
import objcTests.*
|
||||
|
||||
class KT38234_Impl : KT38234_P1Protocol, KT38234_Base() {
|
||||
override fun foo(): Int = 566
|
||||
}
|
||||
|
||||
@Test fun testKT38234() {
|
||||
assertEquals(566, KT38234_Impl().callFoo())
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "KT38234_override.h"
|
||||
|
||||
@implementation KT38234_Base
|
||||
-(int)foo {
|
||||
return 1;
|
||||
}
|
||||
-(int)callFoo {
|
||||
return [self foo];
|
||||
}
|
||||
@end;
|
||||
Reference in New Issue
Block a user