Apply interop lowering to new declarations it produces
#KT-36182 Fixed
This commit is contained in:
committed by
SvyatoslavScherbina
parent
b46200bc74
commit
2cf079abed
+11
-1
@@ -815,7 +815,17 @@ private class InteropLoweringPart2(val context: Context) : FileLoweringPass {
|
||||
val transformer = InteropTransformer(context, irFile)
|
||||
irFile.transformChildrenVoid(transformer)
|
||||
|
||||
irFile.addChildren(transformer.newTopLevelDeclarations)
|
||||
while (transformer.newTopLevelDeclarations.isNotEmpty()) {
|
||||
val newTopLevelDeclarations = transformer.newTopLevelDeclarations.toList()
|
||||
transformer.newTopLevelDeclarations.clear()
|
||||
|
||||
// Assuming these declarations contain only new IR (i.e. existing lowered IR has not been moved there).
|
||||
// TODO: make this more reliable.
|
||||
val loweredNewTopLevelDeclarations =
|
||||
newTopLevelDeclarations.map { it.transform(transformer, null) as IrDeclaration }
|
||||
|
||||
irFile.addChildren(loweredNewTopLevelDeclarations)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,22 @@ import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
import ccallbacksAndVarargs.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fun main() {
|
||||
testStructCallbacks()
|
||||
testVarargs()
|
||||
testCallableReferences()
|
||||
}
|
||||
|
||||
fun testStructCallbacks() {
|
||||
assertEquals(42, getX(staticCFunction { -> cValue<S> { x = 42 } }))
|
||||
applyCallback(cValue { x = 17 }, staticCFunction { it: CValue<S> ->
|
||||
assertEquals(17, it.useContents { x })
|
||||
})
|
||||
|
||||
assertEquals(66, makeS(66, 111).useContents { x })
|
||||
}
|
||||
|
||||
fun testVarargs() {
|
||||
assertEquals(E.ONE, makeE(1))
|
||||
|
||||
getVarargs(
|
||||
@@ -51,3 +60,11 @@ fun main(args: Array<String>) {
|
||||
assertEquals(null, a15)
|
||||
}
|
||||
}
|
||||
|
||||
fun testCallableReferences() {
|
||||
val sumRef = ::sum
|
||||
assertEquals(3, sumRef(1, 2))
|
||||
|
||||
val sumPtr = staticCFunction(::sum)
|
||||
assertEquals(7, sumPtr(3, 4))
|
||||
}
|
||||
|
||||
@@ -72,3 +72,7 @@ static struct Args getVarargs(int ignore, ...) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int sum(int first, int second) {
|
||||
return first + second;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user