From 51d03ece0aa24fc386a9ee77e3be50504fd85cdb Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Thu, 5 Sep 2019 16:28:07 +0300 Subject: [PATCH] Fixed fast type check for ObjC classes + test --- backend.native/tests/framework/values/expectedLazy.h | 7 +++++++ backend.native/tests/framework/values/values.kt | 4 ++++ backend.native/tests/framework/values/values.swift | 7 +++++++ runtime/src/main/cpp/ObjCExport.mm | 2 ++ 4 files changed, 20 insertions(+) diff --git a/backend.native/tests/framework/values/expectedLazy.h b/backend.native/tests/framework/values/expectedLazy.h index 5a8a8c3ac30..3b5e3682605 100644 --- a/backend.native/tests/framework/values/expectedLazy.h +++ b/backend.native/tests/framework/values/expectedLazy.h @@ -983,6 +983,12 @@ __attribute__((swift_name("SharedRefs.MutableData"))) @property int32_t x __attribute__((swift_name("x"))); @end; +__attribute__((swift_name("ClassForTypeCheck"))) +@interface ValuesClassForTypeCheck : KotlinBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +@end; + @interface ValuesEnumeration (ValuesKt) - (ValuesEnumeration *)getAnswer __attribute__((swift_name("getAnswer()"))); @end; @@ -1062,6 +1068,7 @@ __attribute__((swift_name("ValuesKt"))) + (void)error __attribute__((swift_name("error()"))) __attribute__((unavailable("error"))); + (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning"))); + (void)gc __attribute__((swift_name("gc()"))); ++ (BOOL)testClassTypeCheckX:(id)x __attribute__((swift_name("testClassTypeCheck(x:)"))); @property (class, readonly) double dbl __attribute__((swift_name("dbl"))); @property (class, readonly) float flt __attribute__((swift_name("flt"))); @property (class, readonly) int32_t integer __attribute__((swift_name("integer"))); diff --git a/backend.native/tests/framework/values/values.kt b/backend.native/tests/framework/values/values.kt index c32fe4470bc..7222e341468 100644 --- a/backend.native/tests/framework/values/values.kt +++ b/backend.native/tests/framework/values/values.kt @@ -774,3 +774,7 @@ class SharedRefs { private val mustBeRemoved = mutableListOf>() } + +open class ClassForTypeCheck + +fun testClassTypeCheck(x: Any) = x is ClassForTypeCheck \ No newline at end of file diff --git a/backend.native/tests/framework/values/values.swift b/backend.native/tests/framework/values/values.swift index be34a30bee1..60d6403e6ff 100644 --- a/backend.native/tests/framework/values/values.swift +++ b/backend.native/tests/framework/values/values.swift @@ -998,6 +998,12 @@ func testGH2931() throws { } } +class ClassForTypeCheckInheritor : ClassForTypeCheck { } + +func testClassTypeCheck() throws { + try assertTrue(ValuesKt.testClassTypeCheck(x: ClassForTypeCheckInheritor())) +} + // -------- Execution of the test -------- class ValuesTests : TestProvider { @@ -1047,6 +1053,7 @@ class ValuesTests : TestProvider { TestCase(name: "TestDeprecation", method: withAutorelease(testDeprecation)), TestCase(name: "TestWeakRefs", method: withAutorelease(testWeakRefs)), TestCase(name: "TestSharedRefs", method: withAutorelease(TestSharedRefs().test)), + TestCase(name: "TestClassTypeCheck", method: withAutorelease(testClassTypeCheck)), TestCase(name: "TestGH2931", method: withAutorelease(testGH2931)), ] } diff --git a/runtime/src/main/cpp/ObjCExport.mm b/runtime/src/main/cpp/ObjCExport.mm index b40e4bf0ef6..93e9228b61e 100644 --- a/runtime/src/main/cpp/ObjCExport.mm +++ b/runtime/src/main/cpp/ObjCExport.mm @@ -734,6 +734,8 @@ static const TypeInfo* createTypeInfo( result->flags_ |= TF_IMMUTABLE; } + result->classId_ = superType->classId_; + KStdVector implementedInterfaces( superType->implementedInterfaces_, superType->implementedInterfaces_ + superType->implementedInterfacesCount_ );