From 94145f880c4dba5b63807d43dd9c0c9223e47b69 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Thu, 29 Oct 2020 13:14:25 +0500 Subject: [PATCH] [IR] Inliner: supported recursion in default arguments --- .../common/lower/inline/FunctionInlining.kt | 16 +++++++++++----- .../recursiveDefaultArguments.kt | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt index 542d94bb198..370e2487544 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt @@ -162,11 +162,17 @@ class FunctionInlining( callee: IrFunction, performRecursiveInline: Boolean ): IrReturnableBlock { - val copiedCallee = copyIrElement.copy(callee).let { - (it as IrFunction).parent = callee.parent - if (performRecursiveInline) - visitElement(it) as IrFunction - else it + val copiedCallee = (copyIrElement.copy(callee) as IrFunction).apply { + parent = callee.parent + if (performRecursiveInline) { + body?.transformChildrenVoid() + valueParameters.forEachIndexed { index, param -> + if (callSite.getValueArgument(index) == null) { + // Default values can recursively reference [callee] - transform only needed. + param.defaultValue = param.defaultValue?.transform(this@FunctionInlining, null) + } + } + } } val evaluationStatements = evaluateArguments(callSite, copiedCallee) diff --git a/compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt b/compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt index cc58156bece..7d4eb69d622 100644 --- a/compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt +++ b/compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt @@ -1,4 +1,4 @@ -// IGNORE_BACKEND: JS, JS_IR +// IGNORE_BACKEND: JS @Suppress("RECURSION_IN_INLINE") inline fun test(p: String = test("OK")): String { return p