diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index f4fa2a9e5fd..450ab348685 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -949,6 +949,12 @@ abstract class ObjCExportHeaderGenerator internal constructor( add("#pragma clang diagnostic push") listOf( "-Wunknown-warning-option", + + // Protocols don't have generics, classes do. So generated header may contain + // overriding property with "incompatible" type, e.g. `Generic`-typed property + // overriding `Generic`. Suppress these warnings: + "-Wincompatible-property-type", + "-Wnullability" ).forEach { add("#pragma clang diagnostic ignored \"$it\"") diff --git a/backend.native/tests/objcexport/expectedLazy.h b/backend.native/tests/objcexport/expectedLazy.h index a233bc6e11c..5cbcfc4a04e 100644 --- a/backend.native/tests/objcexport/expectedLazy.h +++ b/backend.native/tests/objcexport/expectedLazy.h @@ -204,6 +204,33 @@ __attribute__((swift_name("GH4002Argument"))) + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); @end; +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("TestIncompatiblePropertyTypeWarning"))) +@interface KtTestIncompatiblePropertyTypeWarning : KtBase +- (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("TestIncompatiblePropertyTypeWarningGeneric"))) +@interface KtTestIncompatiblePropertyTypeWarningGeneric : KtBase +- (instancetype)initWithValue:(T _Nullable)value __attribute__((swift_name("init(value:)"))) __attribute__((objc_designated_initializer)); +@property (readonly) T _Nullable value __attribute__((swift_name("value"))); +@end; + +__attribute__((swift_name("TestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty"))) +@protocol KtTestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty +@required +@property (readonly) KtTestIncompatiblePropertyTypeWarningGeneric *p __attribute__((swift_name("p"))); +@end; + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("TestIncompatiblePropertyTypeWarning.ClassOverridingInterfaceWithGenericProperty"))) +@interface KtTestIncompatiblePropertyTypeWarningClassOverridingInterfaceWithGenericProperty : KtBase +- (instancetype)initWithP:(KtTestIncompatiblePropertyTypeWarningGeneric *)p __attribute__((swift_name("init(p:)"))) __attribute__((objc_designated_initializer)); +@property (readonly) KtTestIncompatiblePropertyTypeWarningGeneric *p __attribute__((swift_name("p"))); +@end; + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("Kt35940Kt"))) @interface KtKt35940Kt : KtBase diff --git a/backend.native/tests/objcexport/headerWarnings.kt b/backend.native/tests/objcexport/headerWarnings.kt new file mode 100644 index 00000000000..7894eeccd33 --- /dev/null +++ b/backend.native/tests/objcexport/headerWarnings.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2020 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 headerWarnings + +// Note: the test parses the generated header with -Werror to detect warnings. + +class TestIncompatiblePropertyTypeWarning { + class Generic(val value: T) + + interface InterfaceWithGenericProperty { + val p: Generic + } + + class ClassOverridingInterfaceWithGenericProperty(override val p: Generic) : InterfaceWithGenericProperty +} diff --git a/backend.native/tests/objcexport/headerWarnings.swift b/backend.native/tests/objcexport/headerWarnings.swift new file mode 100644 index 00000000000..afd0064b9d6 --- /dev/null +++ b/backend.native/tests/objcexport/headerWarnings.swift @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2020 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 + +// Note: the test parses the generated header with -Werror to detect warnings. +// It is enough to have just Kotlin declarations at the moment. +// Adding usages for all declarations to avoid any kind of DCE that may appear later. + +private func testIncompatiblePropertyType() throws { + let c = TestIncompatiblePropertyTypeWarning.ClassOverridingInterfaceWithGenericProperty( + p: TestIncompatiblePropertyTypeWarningGeneric(value: "cba") + ) + + let pc: TestIncompatiblePropertyTypeWarningGeneric = c.p + try assertEquals(actual: pc.value, expected: "cba") + + let i: TestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty = c + let pi: TestIncompatiblePropertyTypeWarningGeneric = i.p + try assertEquals(actual: pi.value as! String, expected: "cba") +} + +class HeaderWarningsTests : SimpleTestProvider { + override init() { + super.init() + + test("TestIncompatiblePropertyType", testIncompatiblePropertyType) + } +} \ No newline at end of file