Fix Objective-C header for deeply nested classes (#2712)

Fix #2667
This commit is contained in:
SvyatoslavScherbina
2019-02-25 13:39:15 +03:00
committed by Nikolay Igotti
parent 4e90171efa
commit 0ec1712f75
3 changed files with 26 additions and 1 deletions
@@ -184,7 +184,22 @@ internal class ObjCExportNamerImpl(
if (containingDeclaration is ClassDescriptor) {
append(getClassOrProtocolSwiftName(containingDeclaration))
if (!descriptor.isInterface && !containingDeclaration.isInterface) {
val importAsMember = when {
descriptor.isInterface || containingDeclaration.isInterface -> {
// Swift doesn't support neither nested nor outer protocols.
false
}
this.contains('.') -> {
// Swift doesn't support swift_name with deeply nested names.
// It seems to support "OriginalObjCName.SwiftName" though,
// but this doesn't seem neither documented nor reliable.
false
}
else -> true
}
if (importAsMember) {
append(".").append(descriptor.name.asString())
} else {
append(descriptor.name.asString().capitalize())
@@ -269,3 +269,12 @@ fun Any.same() = this
// https://github.com/JetBrains/kotlin-native/issues/2571
val PROPERTY_NAME_MUST_NOT_BE_ALTERED_BY_SWIFT = 111
// https://github.com/JetBrains/kotlin-native/issues/2667
class Deeply {
class Nested {
class Type {
val thirtyTwo = 32
}
}
}
@@ -492,6 +492,7 @@ func testPureSwiftClasses() throws {
func testNames() throws {
try assertEquals(actual: ValuesKt.PROPERTY_NAME_MUST_NOT_BE_ALTERED_BY_SWIFT, expected: 111)
try assertEquals(actual: Deeply.NestedType().thirtyTwo, expected: 32)
}
// -------- Execution of the test --------