Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mangle parameter names clashing with C keywords when producing framework
  • Loading branch information
SvyatoslavScherbina committed Nov 30, 2018
1 parent ce5a0c3 commit 132e12b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private operator fun String.times(count: Int): String {
return builder.toString()
}

private val cKeywords = setOf(
internal val cKeywords = setOf(
// Actual C keywords.
"auto", "break", "case",
"char", "const", "continue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ abstract class ObjCExportHeaderGenerator(
fun collectParameters(baseMethodBridge: MethodBridge, method: FunctionDescriptor): List<ObjCParameter> {
fun unifyName(initialName: String, usedNames: Set<String>): String {
var unique = initialName
while (unique in usedNames) {
while (unique in usedNames || unique in cKeywords) {
unique += "_"
}
return unique
Expand Down
2 changes: 2 additions & 0 deletions backend.native/tests/framework/values/values.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,5 @@ fun IC3?.getValueOrNull3() = this?.value

fun isFrozen(obj: Any): Boolean = obj.isFrozen
fun kotlinLambda(block: (Any) -> Any): Any = block

fun multiply(int: Int, long: Long) = int * long
2 changes: 2 additions & 0 deletions backend.native/tests/framework/values/values.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func testFunctions() throws {

try assertEquals(actual: ValuesKt.argsFun(i: 10, l: 20, d: 3.5, s: "res") as! String,
expected: "res10203.5")

try assertEquals(actual: ValuesKt.multiply(int: 3, long: 2), expected: 6)
}

func testFuncType() throws {
Expand Down

0 comments on commit 132e12b

Please sign in to comment.