Repository: JetBrains/kotlin
File: compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt (Kotlin)

Code before:

                if (argument.isImmutableVariableLoad) {
                    substituteMap[parameter] = variableInitializer
                    return@forEach
                }

                val argumentExtracted = !argument.argumentExpression.isPure(false, context = context)
                if (!argumentExtracted) {
                    substituteMap[parameter] = variableInitializer
                } else {
                    substituteParameterViaTemporaryVariable()
                }
            }
            return evaluationStatements
        }

        private fun createTemporaryVariable(parameter: IrValueParameter, variableInitializer: IrExpression, callee: IrFunction): IrVariable {
            val variable = currentScope.scope.createTemporaryVariable(
                irExpression = IrBlockImpl(
                    variableInitializer.startOffset,
                    variableInitializer.endOffset,
                    variableInitializer.type,
                    InlinerExpressionLocationHint((currentScope.irElement as IrSymbolOwner).symbol)
                ).apply {
                    statements.add(variableInitializer)
                },
                nameHint = callee.symbol.owner.name.toString(),
                isMutable = false,
                origin = if (parameter == callee.extensionReceiverParameter) {
                    IrDeclarationOrigin.IR_TEMPORARY_VARIABLE_FOR_INLINED_EXTENSION_RECEIVER
                } else {
                    IrDeclarationOrigin.IR_TEMPORARY_VARIABLE_FOR_INLINED_PARAMETER
                }
            )

            if (alwaysCreateTemporaryVariablesForArguments) {
                variable.name = parameter.name
            }

            return variable
        }
    }

    private class IrGetValueWithoutLocation(
        override val symbol: IrValueSymbol,
        override val origin: IrStatementOrigin? = null
    ) : IrGetValue() {
        override val startOffset: Int get() = UNDEFINED_OFFSET
        override val endOffset: Int get() = UNDEFINED_OFFSET

        override var type: IrType

Review comment (suggestion):
I'm not sure if we should name the temporary variables like arguments only if the `alwaysCreateTemporaryVariablesForArguments` option is enabled or in all cases.

Code after:
            return evaluationStatements
        }

        private fun ParameterToArgument.shouldBeSubstitutedViaTemporaryVariable(): Boolean =
            !isImmutableVariableLoad && !argumentExpression.isPure(false, context = context)

        private fun createTemporaryVariable(parameter: IrValueParameter, variableInitializer: IrExpression, callee: IrFunction): IrVariable {
            val variable = currentScope.scope.createTemporaryVariable(
                irExpression = IrBlockImpl(
                    variableInitializer.startOffset,
                    variableInitializer.endOffset,
                    variableInitializer.type,
                    InlinerExpressionLocationHint((currentScope.irElement as IrSymbolOwner).symbol)
                ).apply {
                    statements.add(variableInitializer)
                },
                nameHint = callee.symbol.owner.name.toString(),
                isMutable = false,
                origin = if (parameter == callee.extensionReceiverParameter) {
                    IrDeclarationOrigin.IR_TEMPORARY_VARIABLE_FOR_INLINED_EXTENSION_RECEIVER
                } else {
                    IrDeclarationOrigin.IR_TEMPORARY_VARIABLE_FOR_INLINED_PARAMETER
                }
            )

            if (alwaysCreateTemporaryVariablesForArguments) {
                variable.name = parameter.name
            }

            return variable
        }
    }

    private class IrGetValueWithoutLocation(
        override val symbol: IrValueSymbol,
        override val origin: IrStatementOrigin? = null
    ) : IrGetValue() {
        override val startOffset: Int get() = UNDEFINED_OFFSET
        override val endOffset: Int get() = UNDEFINED_OFFSET

        override var type: IrType
            get() = symbol.owner.type
            set(value) {
                symbol.owner.type = value
            }

        override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D) =
            visitor.visitGetValue(this, data)

        fun withLocation(startOffset: Int, endOffset: Int) =
            IrGetValueImpl(startOffset, endOffset, type, symbol, origin)