Fixed bug in inliner with default args + test

This commit is contained in:
Igor Chevdar
2018-07-17 19:00:54 +03:00
parent 3b024dc5ac
commit 4645f86225
3 changed files with 25 additions and 1 deletions
@@ -448,11 +448,16 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
* For simplicity and to produce simpler IR we don't create temporaries for every immutable variable,
* not only for those referring to inlinable lambdas.
*/
if (it.isInlinableLambdaArgument || it.isImmutableVariableLoad) {
if (it.isInlinableLambdaArgument) {
substituteMap[parameterDescriptor] = it.argumentExpression
return@forEach
}
if (it.isImmutableVariableLoad) {
substituteMap[parameterDescriptor] = it.argumentExpression.transform(substitutor, data = null) // Arguments may reference the previous ones - substitute them.
return@forEach
}
val newVariable = currentScope.scope.createTemporaryVariable( // Create new variable and init it with the parameter expression.
irExpression = it.argumentExpression.transform(substitutor, data = null), // Arguments may reference the previous ones - substitute them.
nameHint = functionDeclaration.descriptor.name.toString(),
+5
View File
@@ -2466,6 +2466,11 @@ task inline_changingCapturedLocal(type: RunKonanTest) {
source = "codegen/inline/changingCapturedLocal.kt"
}
task inline_defaultArgs(type: RunKonanTest) {
goldValue = "42\n"
source = "codegen/inline/defaultArgs.kt"
}
task deserialized_inline0(type: RunKonanTest) {
source = "serialization/deserialized_inline0.kt"
}
@@ -0,0 +1,14 @@
package codegen.inline.defaultArgs
import kotlin.test.*
class Z
inline fun Z.foo(x: Int = 42, y: Int = x) {
println(y)
}
@Test fun runTest() {
val z = Z()
z.foo()
}