ObjCExport: fix noAutorelease/testReceiveBlockFromSwiftAndCall
The test expects to track block result lifetime in Swift, so we should add it to the tracker. Also fix the same problem for testReceiveBlockFromKotlinAndCall (which didn't fail because we added the block itself to the tracker).
This commit is contained in:
committed by
Space
parent
d018031cbf
commit
d161108be3
@@ -54,7 +54,7 @@ class NoAutoreleaseKotlinReceiveHelper(val kotlinLivenessTracker: KotlinLiveness
|
||||
private val list = listOf(Any())
|
||||
private val string = Any().toString()
|
||||
private val number = createKotlinNumber()
|
||||
private val block = createLambda()
|
||||
private val block = createLambda(kotlinLivenessTracker)
|
||||
|
||||
override fun receiveKotlinObject(): KotlinObject = kotlinObject.also { kotlinLivenessTracker.add(it) }
|
||||
override fun receiveSwiftObject(): Any = swiftObject.also { kotlinLivenessTracker.add(it) }
|
||||
@@ -158,4 +158,13 @@ private fun createLambda(): () -> KotlinObject {
|
||||
return { lambdaResult } // make it capturing thus dynamic.
|
||||
}
|
||||
|
||||
private fun createLambda(kotlinLivenessTracker: KotlinLivenessTracker): () -> KotlinObject {
|
||||
val lambdaResult = KotlinObject()
|
||||
return {
|
||||
val result = lambdaResult // make it capturing thus dynamic.
|
||||
kotlinLivenessTracker.add(result)
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
private fun createKotlinNumber(): Any = (0.5 + Any().hashCode().toDouble()) // to make it dynamic.
|
||||
|
||||
@@ -62,7 +62,7 @@ private class NoAutoreleaseSwiftHelper : NoAutoreleaseSendHelper, NoAutoreleaseR
|
||||
let list = createList()
|
||||
let string = createString()
|
||||
let number = createNumber()
|
||||
let block = createBlock()
|
||||
lazy var block = createBlock(swiftLivenessTracker: swiftLivenessTracker)
|
||||
|
||||
func receiveKotlinObject() -> KotlinObject {
|
||||
let result = kotlinObject
|
||||
@@ -401,6 +401,15 @@ private func createBlock() -> () -> KotlinObject {
|
||||
return { return blockResult } // Make capturing thus dynamic.
|
||||
}
|
||||
|
||||
private func createBlock(swiftLivenessTracker: SwiftLivenessTracker) -> () -> KotlinObject {
|
||||
let blockResult = KotlinObject()
|
||||
return {
|
||||
let result = blockResult // Make capturing thus dynamic.
|
||||
swiftLivenessTracker.add(result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
private func createString() -> String {
|
||||
return NSObject().description // Make it dynamic.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user