[K/N] Do not export all operator component functions in data classes
^KT-57507
This commit is contained in:
committed by
Space Team
parent
3b0c36da3f
commit
ac8cbcafb4
+5
-6
@@ -78,12 +78,11 @@ private fun isSealedClassConstructor(descriptor: ConstructorDescriptor) = descri
|
||||
* Check that given [method] is a synthetic .componentN() method of a data class.
|
||||
*/
|
||||
private fun isComponentNMethod(method: CallableMemberDescriptor): Boolean {
|
||||
if (method.kind == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||
val parent = method.containingDeclaration
|
||||
if (parent is ClassDescriptor && parent.isData && DataClassResolver.isComponentLike(method.name)) {
|
||||
// componentN method of data class.
|
||||
return true
|
||||
}
|
||||
if ((method as? FunctionDescriptor)?.isOperator != true) return false
|
||||
val parent = method.containingDeclaration
|
||||
if (parent is ClassDescriptor && parent.isData && DataClassResolver.isComponentLike(method.name)) {
|
||||
// componentN method of data class.
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -24,3 +24,8 @@ class RegularClassWithComponentMethods {
|
||||
|
||||
fun component1() = 5
|
||||
fun component4() = 6
|
||||
|
||||
data class DataClassWithStrangeNames(val component124: Int, val componentABC: Int) {
|
||||
operator fun component15() = component124
|
||||
fun component16() = component124
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ private func testTopLevelComponentMethodsAreAccessible() throws {
|
||||
try assertEquals(actual: DataClassComponentMethodsKt.component4(), expected: 6)
|
||||
}
|
||||
|
||||
private func testComponentExportedOrNot() throws {
|
||||
try assertFalse(class_respondsToSelector(object_getClass(DataClassWithStrangeNames.self), NSSelectorFromString("component1")));
|
||||
try assertFalse(class_respondsToSelector(object_getClass(DataClassWithStrangeNames.self), NSSelectorFromString("component2")));
|
||||
try assertFalse(class_respondsToSelector(object_getClass(DataClassWithStrangeNames.self), NSSelectorFromString("component15")));
|
||||
let r = DataClassWithStrangeNames(component124: 1, componentABC:2)
|
||||
try assertEquals(actual: r.component124, expected: 1)
|
||||
try assertEquals(actual: r.componentABC, expected: 2)
|
||||
try assertEquals(actual: r.component16(), expected: 1)
|
||||
}
|
||||
|
||||
class DataClassComponentMethodsTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
@@ -34,5 +44,6 @@ class DataClassComponentMethodsTests : SimpleTestProvider {
|
||||
test("testCustomComponentMethodsAreAccessible", testCustomComponentMethodsAreAccessible)
|
||||
test("testRegularComponentMethodsAreAccessible", testRegularComponentMethodsAreAccessible)
|
||||
test("testTopLevelComponentMethodsAreAccessible", testTopLevelComponentMethodsAreAccessible)
|
||||
test("testComponentExportedOrNot", testComponentExportedOrNot)
|
||||
}
|
||||
}
|
||||
@@ -450,6 +450,19 @@ __attribute__((swift_name("RegularClassWithComponentMethods")))
|
||||
- (int32_t)component3 __attribute__((swift_name("component3()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("DataClassWithStrangeNames")))
|
||||
@interface KtDataClassWithStrangeNames : KtBase
|
||||
- (instancetype)initWithComponent124:(int32_t)component124 componentABC:(int32_t)componentABC __attribute__((swift_name("init(component124:componentABC:)"))) __attribute__((objc_designated_initializer));
|
||||
- (int32_t)component16 __attribute__((swift_name("component16()")));
|
||||
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
|
||||
- (NSUInteger)hash __attribute__((swift_name("hash()")));
|
||||
- (NSString *)description __attribute__((swift_name("description()")));
|
||||
- (KtDataClassWithStrangeNames *)doCopyComponent124:(int32_t)component124 componentABC:(int32_t)componentABC __attribute__((swift_name("doCopy(component124:componentABC:)")));
|
||||
@property (readonly) int32_t component124 __attribute__((swift_name("component124")));
|
||||
@property (readonly) int32_t componentABC __attribute__((swift_name("componentABC")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("DataClassComponentMethodsKt")))
|
||||
@interface KtDataClassComponentMethodsKt : KtBase
|
||||
|
||||
@@ -450,6 +450,19 @@ __attribute__((swift_name("RegularClassWithComponentMethods")))
|
||||
- (int32_t)component3 __attribute__((swift_name("component3()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("DataClassWithStrangeNames")))
|
||||
@interface KtDataClassWithStrangeNames : KtBase
|
||||
- (instancetype)initWithComponent124:(int32_t)component124 componentABC:(int32_t)componentABC __attribute__((swift_name("init(component124:componentABC:)"))) __attribute__((objc_designated_initializer));
|
||||
- (int32_t)component16 __attribute__((swift_name("component16()")));
|
||||
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
|
||||
- (NSUInteger)hash __attribute__((swift_name("hash()")));
|
||||
- (NSString *)description __attribute__((swift_name("description()")));
|
||||
- (KtDataClassWithStrangeNames *)doCopyComponent124:(int32_t)component124 componentABC:(int32_t)componentABC __attribute__((swift_name("doCopy(component124:componentABC:)")));
|
||||
@property (readonly) int32_t component124 __attribute__((swift_name("component124")));
|
||||
@property (readonly) int32_t componentABC __attribute__((swift_name("componentABC")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("DataClassComponentMethodsKt")))
|
||||
@interface KtDataClassComponentMethodsKt : KtBase
|
||||
|
||||
@@ -450,6 +450,19 @@ __attribute__((swift_name("RegularClassWithComponentMethods")))
|
||||
- (int32_t)component3 __attribute__((swift_name("component3()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("DataClassWithStrangeNames")))
|
||||
@interface KtDataClassWithStrangeNames : KtBase
|
||||
- (instancetype)initWithComponent124:(int32_t)component124 componentABC:(int32_t)componentABC __attribute__((swift_name("init(component124:componentABC:)"))) __attribute__((objc_designated_initializer));
|
||||
- (int32_t)component16 __attribute__((swift_name("component16()")));
|
||||
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
|
||||
- (NSUInteger)hash __attribute__((swift_name("hash()")));
|
||||
- (NSString *)description __attribute__((swift_name("description()")));
|
||||
- (KtDataClassWithStrangeNames *)doCopyComponent124:(int32_t)component124 componentABC:(int32_t)componentABC __attribute__((swift_name("doCopy(component124:componentABC:)")));
|
||||
@property (readonly) int32_t component124 __attribute__((swift_name("component124")));
|
||||
@property (readonly) int32_t componentABC __attribute__((swift_name("componentABC")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("DataClassComponentMethodsKt")))
|
||||
@interface KtDataClassComponentMethodsKt : KtBase
|
||||
|
||||
Reference in New Issue
Block a user