Skip to content

Commit b12d4a7

Browse files
elevenetcSpace Team
authored andcommitted
[ObjCExport] Fix property getter translation
^KT-79475 Fixed
1 parent 68a029a commit b12d4a7

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

native/objcexport-header-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCPropertyGetter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal fun ObjCExportContext.getObjCPropertyGetter(symbol: KaPropertySymbol, o
2222

2323
val symbolGetter = symbol.getter
2424
val getterBridge = if (symbolGetter == null) error("KtPropertySymbol.getter is undefined") else getFunctionMethodBridge(symbolGetter)
25-
val getterSelector = getSelector(symbolGetter, getterBridge)
25+
val getterSelector = getSelector(symbolGetter, getterBridge, true)
2626

2727
return if (getterSelector != objCName && getterSelector.isNotBlank()) getterSelector else null
2828
}

native/objcexport-header-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/translateToObjCMethod.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ internal fun splitSelector(selector: String): List<String> {
223223
/**
224224
* [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamerImpl.getSelector]
225225
*/
226-
fun ObjCExportContext.getSelector(symbol: KaFunctionSymbol, methodBridge: MethodBridge): String {
226+
fun ObjCExportContext.getSelector(symbol: KaFunctionSymbol, methodBridge: MethodBridge, isPropertyGetter: Boolean = false): String {
227227

228228
val parameters = valueParametersAssociated(methodBridge, symbol)
229229
val method = symbol
@@ -284,7 +284,7 @@ fun ObjCExportContext.getSelector(symbol: KaFunctionSymbol, methodBridge: Method
284284
sb.append(name)
285285
}
286286

287-
sb.append(':')
287+
if (!isPropertyGetter) sb.append(':')
288288
}
289289
return sb.toString()
290290
}

native/objcexport-header-generator/test/org/jetbrains/kotlin/backend/konan/tests/ObjCExportHeaderGeneratorTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ class ObjCExportHeaderGeneratorTest(private val generator: HeaderGenerator) {
665665
doTest(headersTestDataDir.resolve("anyMethodsOverride"))
666666
}
667667

668+
@Test
669+
fun `test - property getter without colon`() {
670+
doTest(headersTestDataDir.resolve("propertyGetter"))
671+
}
672+
668673
private fun doTest(root: File, configuration: Configuration = Configuration()) {
669674
if (!root.isDirectory) fail("Expected ${root.absolutePath} to be directory")
670675
val generatedHeaders = generator.generateHeaders(root, configuration).toString()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#import <Foundation/NSArray.h>
2+
#import <Foundation/NSDictionary.h>
3+
#import <Foundation/NSError.h>
4+
#import <Foundation/NSObject.h>
5+
#import <Foundation/NSSet.h>
6+
#import <Foundation/NSString.h>
7+
#import <Foundation/NSValue.h>
8+
9+
@class Foo;
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
#pragma clang diagnostic push
13+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
14+
#pragma clang diagnostic ignored "-Wincompatible-property-type"
15+
#pragma clang diagnostic ignored "-Wnullability"
16+
17+
#pragma push_macro("_Nullable_result")
18+
#if !__has_feature(nullability_nullable_result)
19+
#undef _Nullable_result
20+
#define _Nullable_result _Nullable
21+
#endif
22+
23+
__attribute__((objc_subclassing_restricted))
24+
@interface Foo : Base
25+
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
26+
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
27+
@end
28+
29+
@interface Foo (Extensions)
30+
@property (readonly, getter=double) double double_ __attribute__((swift_name("double_")));
31+
@end
32+
33+
#pragma pop_macro("_Nullable_result")
34+
#pragma clang diagnostic pop
35+
NS_ASSUME_NONNULL_END
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Foo
2+
val Foo.double: Double get() = 42.0

0 commit comments

Comments
 (0)