Fixed inline call arguments evaluation + test
This commit is contained in:
committed by
Igor Chevdar
parent
cf5e6dac80
commit
295f71a29c
+2
-2
@@ -125,13 +125,13 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
|
||||
private fun inlineFunction(irCall : IrCall, // Call to be substituted.
|
||||
functionDeclaration: IrFunction): IrReturnableBlockImpl { // Function to substitute.
|
||||
|
||||
val evaluationStatements = evaluateArguments(irCall, functionDeclaration) // And list of evaluation statements.
|
||||
|
||||
val copyFunctionDeclaration = copyIrElement.copy( // Create copy of original function.
|
||||
irElement = functionDeclaration, // Descriptors declared inside the function will be copied.
|
||||
typeSubstitutor = createTypeSubstitutor(irCall) // Type parameters will be substituted with type arguments.
|
||||
) as IrFunction
|
||||
|
||||
val evaluationStatements = evaluateArguments(irCall, copyFunctionDeclaration) // And list of evaluation statements.
|
||||
|
||||
val statements = (copyFunctionDeclaration.body as IrBlockBody).statements // IR statements from function copy.
|
||||
val returnType = copyFunctionDeclaration.descriptor.returnType!! // Substituted return type.
|
||||
val sourceFileName = context.ir.originalModuleIndex.declarationToFile[functionDeclaration.descriptor.original]?:""
|
||||
|
||||
@@ -2096,6 +2096,11 @@ task inline_localFunctionInInitializerBlock(type: RunKonanTest) {
|
||||
source = "codegen/inline/localFunctionInInitializerBlock.kt"
|
||||
}
|
||||
|
||||
task inline_lambdaInDefaultValue(type: RunKonanTest) {
|
||||
goldValue = "OK\n"
|
||||
source = "codegen/inline/lambdaInDefaultValue.kt"
|
||||
}
|
||||
|
||||
task deserialized_inline0(type: RunKonanTest) {
|
||||
source = "serialization/deserialized_inline0.kt"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package codegen.inline.lambdaInDefaultValue
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
inline fun inlineFun(param: String, lambda: (String) -> String = { it }): String {
|
||||
return lambda(param)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return inlineFun("OK")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import global.*
|
||||
import kotlinx.cinterop.*
|
||||
import platform.posix.*
|
||||
|
||||
fun Int.ensureUnixCallResult(op: String, predicate: (Int) -> Boolean = { x -> x == 0} ): Int {
|
||||
inline fun Int.ensureUnixCallResult(op: String, predicate: (Int) -> Boolean = { x -> x == 0} ): Int {
|
||||
if (!predicate(this)) {
|
||||
throw Error("$op: ${strerror(posix_errno())!!.toKString()}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user