Don't use 'Type' as nested class name when producing framework (#3217)

Fix #3167.
This commit is contained in:
SvyatoslavScherbina
2019-08-01 14:14:27 +03:00
committed by GitHub
parent 5cb8d97e2a
commit 11a8fafb2a
4 changed files with 30 additions and 2 deletions
@@ -120,7 +120,7 @@ internal open class ObjCExportNameTranslatorImpl(
}
if (importAsMember) {
append(".").append(ownName)
append(".").append(helper.mangleSwiftNestedClassName(ownName))
} else {
append(ownName.capitalize())
}
@@ -154,6 +154,11 @@ private class ObjCExportNamingHelper(
fun getFileClassName(file: KtFile): ObjCExportNamer.ClassOrProtocolName =
getFileClassName(file.name)
fun mangleSwiftNestedClassName(name: String): String = when (name) {
"Type" -> "${name}_" // See https://github.com/JetBrains/kotlin-native/issues/3167
else -> name
}
}
internal class ObjCExportNamerImpl(
@@ -332,7 +337,7 @@ internal class ObjCExportNamerImpl(
}
val ownName = descriptor.name.asString().toIdentifier()
if (importAsMember) {
append(".").append(ownName)
append(".").append(helper.mangleSwiftNestedClassName(ownName))
} else {
append(ownName.capitalize())
}
@@ -344,6 +344,21 @@ __attribute__((swift_name("WithGenericDeeply.NestedType")))
@property (readonly) int32_t thirtyThree __attribute__((swift_name("thirtyThree")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("TypeOuter")))
@interface ValuesTypeOuter : KotlinBase
- (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("TypeOuter.Type_")))
@interface ValuesTypeOuterType_ : KotlinBase
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@property (readonly) int32_t thirtyFour __attribute__((swift_name("thirtyFour")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("CKeywords")))
@interface ValuesCKeywords : KotlinBase
@@ -290,6 +290,13 @@ class WithGenericDeeply() {
}
}
// https://github.com/JetBrains/kotlin-native/issues/3167
class TypeOuter {
class Type {
val thirtyFour = 34
}
}
data class CKeywords(val float: Float, val `enum`: Int, var goto: Boolean)
interface Base1 {
@@ -532,6 +532,7 @@ func testNames() throws {
try assertEquals(actual: Deeply.NestedType().thirtyTwo, expected: 32)
try assertEquals(actual: WithGenericDeeply.NestedType().thirtyThree, expected: 33)
try assertEquals(actual: CKeywords(float: 1.0, enum : 42, goto: true).goto_, expected: true)
try assertEquals(actual: TypeOuter.Type_().thirtyFour, expected: 34)
}
class Base123 : Base23, ExtendedBase1 {