Fix warnings caused by generics in generated ObjCExport header
This commit is contained in:
committed by
GitHub
parent
06ebfd668e
commit
ba75bcb379
+6
@@ -949,6 +949,12 @@ abstract class ObjCExportHeaderGenerator internal constructor(
|
|||||||
add("#pragma clang diagnostic push")
|
add("#pragma clang diagnostic push")
|
||||||
listOf(
|
listOf(
|
||||||
"-Wunknown-warning-option",
|
"-Wunknown-warning-option",
|
||||||
|
|
||||||
|
// Protocols don't have generics, classes do. So generated header may contain
|
||||||
|
// overriding property with "incompatible" type, e.g. `Generic<T>`-typed property
|
||||||
|
// overriding `Generic<id>`. Suppress these warnings:
|
||||||
|
"-Wincompatible-property-type",
|
||||||
|
|
||||||
"-Wnullability"
|
"-Wnullability"
|
||||||
).forEach {
|
).forEach {
|
||||||
add("#pragma clang diagnostic ignored \"$it\"")
|
add("#pragma clang diagnostic ignored \"$it\"")
|
||||||
|
|||||||
@@ -204,6 +204,33 @@ __attribute__((swift_name("GH4002Argument")))
|
|||||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||||
@end;
|
@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<T> : 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<id> *p __attribute__((swift_name("p")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((objc_subclassing_restricted))
|
||||||
|
__attribute__((swift_name("TestIncompatiblePropertyTypeWarning.ClassOverridingInterfaceWithGenericProperty")))
|
||||||
|
@interface KtTestIncompatiblePropertyTypeWarningClassOverridingInterfaceWithGenericProperty : KtBase <KtTestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty>
|
||||||
|
- (instancetype)initWithP:(KtTestIncompatiblePropertyTypeWarningGeneric<NSString *> *)p __attribute__((swift_name("init(p:)"))) __attribute__((objc_designated_initializer));
|
||||||
|
@property (readonly) KtTestIncompatiblePropertyTypeWarningGeneric<NSString *> *p __attribute__((swift_name("p")));
|
||||||
|
@end;
|
||||||
|
|
||||||
__attribute__((objc_subclassing_restricted))
|
__attribute__((objc_subclassing_restricted))
|
||||||
__attribute__((swift_name("Kt35940Kt")))
|
__attribute__((swift_name("Kt35940Kt")))
|
||||||
@interface KtKt35940Kt : KtBase
|
@interface KtKt35940Kt : KtBase
|
||||||
|
|||||||
@@ -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<T>(val value: T)
|
||||||
|
|
||||||
|
interface InterfaceWithGenericProperty<T> {
|
||||||
|
val p: Generic<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
class ClassOverridingInterfaceWithGenericProperty(override val p: Generic<String>) : InterfaceWithGenericProperty<String>
|
||||||
|
}
|
||||||
@@ -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<NSString>(value: "cba")
|
||||||
|
)
|
||||||
|
|
||||||
|
let pc: TestIncompatiblePropertyTypeWarningGeneric<NSString> = c.p
|
||||||
|
try assertEquals(actual: pc.value, expected: "cba")
|
||||||
|
|
||||||
|
let i: TestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty = c
|
||||||
|
let pi: TestIncompatiblePropertyTypeWarningGeneric<AnyObject> = i.p
|
||||||
|
try assertEquals(actual: pi.value as! String, expected: "cba")
|
||||||
|
}
|
||||||
|
|
||||||
|
class HeaderWarningsTests : SimpleTestProvider {
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
test("TestIncompatiblePropertyType", testIncompatiblePropertyType)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user