diff --git a/plugins/kotlin/idea/tests/testData/refactoring/inline/namedFunction/returnAtEnd/ClassDelegate.kt.after b/plugins/kotlin/idea/tests/testData/refactoring/inline/namedFunction/returnAtEnd/ClassDelegate.kt.after index 04cc4f5c68e5..5e4edd290838 100644 --- a/plugins/kotlin/idea/tests/testData/refactoring/inline/namedFunction/returnAtEnd/ClassDelegate.kt.after +++ b/plugins/kotlin/idea/tests/testData/refactoring/inline/namedFunction/returnAtEnd/ClassDelegate.kt.after @@ -1,5 +1,5 @@ interface DelegateFace -class DelegatingB : DelegateFace by run { +class DelegatingB : DelegateFace by run({ val result = object : DelegateFace {} result -} \ No newline at end of file +}) \ No newline at end of file diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/inline/codeInliner/ReplacementPerformer.kt b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/inline/codeInliner/ReplacementPerformer.kt index cf825646b930..63b660e86874 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/inline/codeInliner/ReplacementPerformer.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/inline/codeInliner/ReplacementPerformer.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange import org.jetbrains.kotlin.psi.psiUtil.canPlaceAfterSimpleNameEntry import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments @@ -285,10 +286,11 @@ class ExpressionReplacementPerformer( } private fun KtElement.replaceWithRunBlockAndGetExpression(): KtExpression { - val runExpression = psiFactory.createExpressionByPattern("run { $0 }", this) as KtCallExpression + val runExpressionText = if (getStrictParentOfType() != null) "run({ $0 })" else "run { $0 }" + val runExpression = psiFactory.createExpressionByPattern(runExpressionText, this) as KtCallExpression val runAfterReplacement = this.replaced(runExpression) - val ktLambdaArgument = runAfterReplacement.lambdaArguments[0] - return ktLambdaArgument.getLambdaExpression()?.bodyExpression?.statements?.singleOrNull() + val ktLambdaArgument = runAfterReplacement.valueArguments[0] + return (ktLambdaArgument.getArgumentExpression() as? KtLambdaExpression)?.bodyExpression?.statements?.singleOrNull() ?: throw KotlinExceptionWithAttachments("cant get body expression for $ktLambdaArgument") .withPsiAttachment("ktLambdaArgument", ktLambdaArgument) }