Fixed bug in inliner with default args + test
This commit is contained in:
+6
-1
@@ -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,
|
* For simplicity and to produce simpler IR we don't create temporaries for every immutable variable,
|
||||||
* not only for those referring to inlinable lambdas.
|
* not only for those referring to inlinable lambdas.
|
||||||
*/
|
*/
|
||||||
if (it.isInlinableLambdaArgument || it.isImmutableVariableLoad) {
|
if (it.isInlinableLambdaArgument) {
|
||||||
substituteMap[parameterDescriptor] = it.argumentExpression
|
substituteMap[parameterDescriptor] = it.argumentExpression
|
||||||
return@forEach
|
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.
|
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.
|
irExpression = it.argumentExpression.transform(substitutor, data = null), // Arguments may reference the previous ones - substitute them.
|
||||||
nameHint = functionDeclaration.descriptor.name.toString(),
|
nameHint = functionDeclaration.descriptor.name.toString(),
|
||||||
|
|||||||
@@ -2466,6 +2466,11 @@ task inline_changingCapturedLocal(type: RunKonanTest) {
|
|||||||
source = "codegen/inline/changingCapturedLocal.kt"
|
source = "codegen/inline/changingCapturedLocal.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task inline_defaultArgs(type: RunKonanTest) {
|
||||||
|
goldValue = "42\n"
|
||||||
|
source = "codegen/inline/defaultArgs.kt"
|
||||||
|
}
|
||||||
|
|
||||||
task deserialized_inline0(type: RunKonanTest) {
|
task deserialized_inline0(type: RunKonanTest) {
|
||||||
source = "serialization/deserialized_inline0.kt"
|
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()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user