diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index 477e4e83c73..74fbf21cf09 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -437,7 +437,7 @@ object PositioningStrategies { @JvmField val DECLARATION_WITH_BODY: PositioningStrategy = object : PositioningStrategy() { override fun mark(element: KtDeclarationWithBody): List { - val lastBracketRange = (element.bodyExpression as? KtBlockExpression)?.lastBracketRange + val lastBracketRange = element.bodyBlockExpression?.lastBracketRange return if (lastBracketRange != null) markRange(lastBracketRange) else @@ -445,7 +445,7 @@ object PositioningStrategies { } override fun isValid(element: KtDeclarationWithBody): Boolean { - return super.isValid(element) && (element.bodyExpression as? KtBlockExpression)?.lastBracketRange != null + return super.isValid(element) && element.bodyBlockExpression?.lastBracketRange != null } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtDeclarationWithBody.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtDeclarationWithBody.java index 85d4e138d8e..e424f6b2d2b 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtDeclarationWithBody.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtDeclarationWithBody.java @@ -41,5 +41,15 @@ public interface KtDeclarationWithBody extends KtDeclaration { @NotNull List getValueParameters(); + + @Nullable + default KtBlockExpression getBodyBlockExpression() { + KtExpression bodyExpression = getBodyExpression(); + if (bodyExpression instanceof KtBlockExpression) { + return (KtBlockExpression) bodyExpression; + } + + return null; + } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt index 587b21ff753..b0f0465c7e8 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt @@ -276,7 +276,7 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m } fun createDestructuringDeclaration(text: String): KtDestructuringDeclaration { - return (createFunction("fun foo() {$text}").bodyExpression as KtBlockExpression).statements.first() as KtDestructuringDeclaration + return createFunction("fun foo() {$text}").bodyBlockExpression!!.statements.first() as KtDestructuringDeclaration } fun createDestructuringParameter(text: String): KtParameter { @@ -337,7 +337,7 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m } fun createEmptyBody(): KtBlockExpression { - return createFunction("fun foo() {}").bodyExpression as KtBlockExpression + return createFunction("fun foo() {}").bodyBlockExpression!! } fun createAnonymousInitializer(): KtAnonymousInitializer { @@ -821,13 +821,13 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m } fun createBlock(bodyText: String): KtBlockExpression { - return createFunction("fun foo() {\n$bodyText\n}").bodyExpression as KtBlockExpression + return createFunction("fun foo() {\n$bodyText\n}").bodyBlockExpression!! } fun createSingleStatementBlock(statement: KtExpression, prevComment: String? = null, nextComment: String? = null): KtBlockExpression { val prev = if (prevComment == null) "" else " $prevComment " val next = if (nextComment == null) "" else " $nextComment " - return createDeclarationByPattern("fun foo() {\n$prev$0$next\n}", statement).bodyExpression as KtBlockExpression + return createDeclarationByPattern("fun foo() {\n$prev$0$next\n}", statement).bodyBlockExpression!! } fun createComment(text: String): PsiComment { diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 332de5ccf23..1376ff2b96f 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub import org.jetbrains.kotlin.types.expressions.OperatorConventions -import java.lang.IllegalArgumentException import java.util.* // NOTE: in this file we collect only Kotlin-specific methods working with PSI and not modifying it @@ -300,7 +299,7 @@ fun KtNamedFunction.isContractPresentPsiCheck(): Boolean { !hasModifier(KtTokens.OPERATOR_KEYWORD) if (!contractAllowedHere) return false - val firstExpression = ((this as? KtFunction)?.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: return false + val firstExpression = (this as? KtFunction)?.bodyBlockExpression?.statements?.firstOrNull() ?: return false return firstExpression.isContractDescriptionCallPsiCheck() } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt index 20f83c667c3..af65e54980e 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt @@ -143,7 +143,7 @@ fun getLambdasAtLineIfAny(file: KtFile, line: Int): List { .toSet() return allLiterals.filter { - val statement = (it.bodyExpression as? KtBlockExpression)?.statements?.firstOrNull() ?: it + val statement = it.bodyBlockExpression?.statements?.firstOrNull() ?: it statement.getLineNumber() == line && statement.getLineNumber(false) == line } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt index 277021ba632..b2699723072 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt @@ -144,7 +144,7 @@ class KotlinCodeFragmentFactory : CodeFragmentFactory() { val fakeFile = createFakeFileWithJavaContextElement(fakeFunctionText, contextElement) val fakeFunction = fakeFile.declarations.firstOrNull() as? KtFunction - val fakeContext = (fakeFunction?.bodyExpression as? KtBlockExpression)?.statements?.lastOrNull() + val fakeContext = fakeFunction?.bodyBlockExpression?.statements?.lastOrNull() return@putCopyableUserData wrapContextIfNeeded(project, contextElement, fakeContext) ?: emptyFile }) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt index b2628bb096f..239eea583b1 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -335,7 +335,7 @@ private fun findElementBefore(contextElement: PsiElement): PsiElement? { wrapInLambdaCall(contextElement.bodyExpression!!) } contextElement is KtDeclarationWithBody && contextElement.hasBlockBody() -> { - val block = contextElement.bodyExpression as KtBlockExpression + val block = contextElement.bodyBlockExpression!! val last = block.statements.lastOrNull() last as? KtReturnExpression ?: block.rBrace } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt index b062be6cf50..3c68f7ecc2b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt @@ -101,7 +101,7 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() { private fun checkGetterBodyIsGetMethodCall(getter: KtPropertyAccessor, getMethod: FunctionDescriptor): Boolean { return if (getter.hasBlockBody()) { - val statement = (getter.bodyExpression as? KtBlockExpression)?.statements?.singleOrNull() ?: return false + val statement = getter.bodyBlockExpression?.statements?.singleOrNull() ?: return false (statement as? KtReturnExpression)?.returnedExpression.isGetMethodCall(getMethod) } else { @@ -112,7 +112,7 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() { private fun checkSetterBodyIsSetMethodCall(setter: KtPropertyAccessor, setMethod: FunctionDescriptor): Boolean { val valueParameterName = setter.valueParameters.singleOrNull()?.nameAsName ?: return false if (setter.hasBlockBody()) { - val statement = (setter.bodyExpression as? KtBlockExpression)?.statements?.singleOrNull() ?: return false + val statement = setter.bodyBlockExpression?.statements?.singleOrNull() ?: return false return statement.isSetMethodCall(setMethod, valueParameterName) } else { diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/SetterBackingFieldAssignmentInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/SetterBackingFieldAssignmentInspection.kt index 34d6c307eb7..b110bc28e45 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/SetterBackingFieldAssignmentInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/SetterBackingFieldAssignmentInspection.kt @@ -21,7 +21,7 @@ class SetterBackingFieldAssignmentInspection : AbstractKotlinInspection(), Clean override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor { return propertyAccessorVisitor(fun(accessor) { if (!accessor.isSetter) return - val bodyExpression = accessor.bodyExpression as? KtBlockExpression ?: return + val bodyExpression = accessor.bodyBlockExpression ?: return val property = accessor.property val propertyContext = property.analyze() @@ -76,7 +76,7 @@ private class AssignBackingFieldFix : LocalQuickFix { override fun applyFix(project: Project, descriptor: ProblemDescriptor) { val setter = descriptor.psiElement as? KtPropertyAccessor ?: return val parameter = setter.valueParameters.firstOrNull() ?: return - val bodyExpression = setter.bodyExpression as? KtBlockExpression ?: return + val bodyExpression = setter.bodyBlockExpression ?: return setter.hasBlockBody() bodyExpression.addBefore( KtPsiFactory(setter).createExpression("field = ${parameter.text}"), diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt index 49da30fa9b8..b67059df549 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt @@ -100,7 +100,7 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs private fun KtDeclarationWithBody.blockExpression() = when (this) { is KtFunctionLiteral -> null - else -> if (!hasBlockBody()) null else bodyExpression as? KtBlockExpression + else -> if (!hasBlockBody()) null else bodyBlockExpression } private fun KtBlockExpression.findValueStatement(): KtExpression? { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index c5e25236889..7a5f7ec4ee3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -88,7 +88,7 @@ class ConvertFunctionToPropertyIntention : SelfTargetingIntention + originalFunction.bodyBlockExpression?.let { body -> transform { append("\nget() ") append(body.text) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt index 5d6714ea434..f2dd490dba7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt @@ -243,7 +243,7 @@ class UsePropertyAccessSyntaxIntention : var callToConvert = callExpression if (callParent is KtDeclarationWithBody && call == callParent.bodyExpression) { ConvertToBlockBodyIntention.convert(callParent) - val firstStatement = (callParent.bodyExpression as? KtBlockExpression)?.statements?.first() + val firstStatement = callParent.bodyBlockExpression?.statements?.first() callToConvert = (firstStatement as? KtQualifiedExpression)?.selectorExpression as? KtCallExpression ?: firstStatement as? KtCallExpression ?: throw IllegalStateException("Unexpected contents of function after conversion: ${callParent.text}") diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/generationUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/generationUtils.kt index 44d2ade8dcd..6b253b3d42c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/generationUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/generationUtils.kt @@ -49,7 +49,7 @@ fun setupEditorSelection(editor: Editor, declaration: KtNamedDeclaration) { when (declaration) { is KtNamedFunction, is KtSecondaryConstructor -> { - ((declaration as KtFunction).bodyExpression as? KtBlockExpression)?.let { + (declaration as KtFunction).bodyBlockExpression?.let { positionBetween(it.lBrace!!, it.rBrace!!) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt index 540a72ddb55..a3477ab1f4e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt @@ -188,7 +188,7 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration) } val setterStubProperty = ktPsiFactory.createProperty("val x: Unit set(value) { Unit }") - val block = setterStubProperty.setter!!.bodyExpression as KtBlockExpression + val block = setterStubProperty.setter!!.bodyBlockExpression!! block.statements.single().replace(setterBody) declaration.add(setterStubProperty.setter!!) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt index 311324c445b..100dc4f4c1c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt @@ -401,7 +401,7 @@ internal fun ExtractionData.createTemporaryCodeBlock(): KtBlockExpression { if (options.extractAsProperty) { return ((createTemporaryDeclaration("val = {\n$0\n}\n") as KtProperty).initializer as KtLambdaExpression).bodyExpression!! } - return (createTemporaryDeclaration("fun() {\n$0\n}\n") as KtNamedFunction).bodyExpression as KtBlockExpression + return (createTemporaryDeclaration("fun() {\n$0\n}\n") as KtNamedFunction).bodyBlockExpression!! } private fun KotlinType.collectReferencedTypes(processTypeArguments: Boolean): List { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt index 6197a65e20c..bcf83465810 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt @@ -244,7 +244,7 @@ class KotlinIntroduceParameterDialog private constructor( project.executeCommand(commandName) { fun createLambdaForArgument(function: KtFunction): KtExpression { - val statement = (function.bodyExpression as KtBlockExpression).statements.single() + val statement = function.bodyBlockExpression!!.statements.single() val space = if (statement.isMultiLine()) "\n" else " " val parameters = function.valueParameters val parametersText = if (parameters.isNotEmpty()) { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt index 074d578d688..f4fc17ff331 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.kt @@ -312,8 +312,8 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler { val newDeclaration = ConvertToBlockBodyIntention.convert(commonContainer) - val newCommonContainer = (newDeclaration.bodyExpression as KtBlockExpression?) - .sure { "New body is not found: " + newDeclaration } + val newCommonContainer = newDeclaration.bodyBlockExpression + .sure { "New body is not found: " + newDeclaration } val newExpression = newCommonContainer.findExpressionByCopyableDataAndClearIt(EXPRESSION_KEY) val newCommonParent = newCommonContainer.findElementByCopyableDataAndClearIt(COMMON_PARENT_KEY) diff --git a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt index 9fcebc9b9f2..2bdf9405f9b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt @@ -80,7 +80,7 @@ class C(param1: String = "", param2: Int = 0) { val klass = file.declarations.single() as KtClass val members = klass.declarations val function = members.first() as KtNamedFunction - val statements = (function.bodyExpression as KtBlockExpression).statements + val statements = function.bodyBlockExpression!!.statements return Data(file, klass, members, statements, KtPsiFactory(project)) } @@ -100,7 +100,7 @@ class C(param1: String = "", param2: Int = 0) { assert(aFunBodyContext3 === aFunBodyContext1) val bFun = members[1] as KtNamedFunction - val bBody = bFun.bodyExpression as KtBlockExpression + val bBody = bFun.bodyBlockExpression!! val bStatement = bBody.statements[0] val bFunBodyContext = bStatement.analyze(BodyResolveMode.FULL) @@ -166,7 +166,7 @@ class C(param1: String = "", param2: Int = 0) { // modify body of "b()" via document val bFun = members[1] as KtNamedFunction - val bBody = bFun.bodyExpression as KtBlockExpression + val bBody = bFun.bodyBlockExpression!! document.insertString(bBody.lBrace!!.startOffset + 1, "x()") documentManager.commitAllDocuments() @@ -427,7 +427,7 @@ class C(param1: String = "", param2: Int = 0) { val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpr] TestCase.assertEquals("Ann", target?.importableFqName?.asString()) - val statement = (function.bodyExpression as KtBlockExpression).statements[0] + val statement = function.bodyBlockExpression!!.statements[0] TestCase.assertEquals(null, bindingContext[BindingContext.PROCESSED, statement]) } @@ -465,17 +465,17 @@ class C(param1: String = "", param2: Int = 0) { val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpr] TestCase.assertEquals("Ann", target?.importableFqName?.asString()) - val statement = (constructor.bodyExpression as KtBlockExpression).statements[0] + val statement = constructor.bodyBlockExpression!!.statements[0] TestCase.assertEquals(null, bindingContext[BindingContext.PROCESSED, statement]) } fun testFullResolveMultiple() { doTest { - val aBody = (members[0] as KtFunction).bodyExpression as KtBlockExpression + val aBody = (members[0] as KtFunction).bodyBlockExpression!! val statement1InFunA = aBody.statements[0] val statement2InFunA = aBody.statements[1] - val statementInFunB = ((members[1] as KtFunction).bodyExpression as KtBlockExpression).statements[0] - val statementInFunC = ((members[2] as KtFunction).bodyExpression as KtBlockExpression).statements[0] + val statementInFunB = ((members[1] as KtFunction).bodyBlockExpression)!!.statements[0] + val statementInFunC = ((members[2] as KtFunction).bodyBlockExpression)!!.statements[0] val bindingContext = checkResolveMultiple(BodyResolveMode.FULL, statement1InFunA, statementInFunB) @@ -486,10 +486,10 @@ class C(param1: String = "", param2: Int = 0) { fun testPartialResolveMultiple() { doTest { - val aBody = (members[0] as KtFunction).bodyExpression as KtBlockExpression + val aBody = (members[0] as KtFunction).bodyBlockExpression!! val statement1InFunA = aBody.statements[0] val statement2InFunA = aBody.statements[1] - val statementInFunB = ((members[1] as KtFunction).bodyExpression as KtBlockExpression).statements[0] + val statementInFunB = ((members[1] as KtFunction).bodyBlockExpression)!!.statements[0] val constructorParameterDefault = klass.getPrimaryConstructor()!!.valueParameters[1].defaultValue!! val funC = members[2] @@ -499,7 +499,7 @@ class C(param1: String = "", param2: Int = 0) { fun testPartialResolveMultipleInOneFunction() { doTest { - val aBody = (members[0] as KtFunction).bodyExpression as KtBlockExpression + val aBody = (members[0] as KtFunction).bodyBlockExpression!! val statement1InFunA = aBody.statements[0] val statement2InFunA = aBody.statements[1] diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt index aeaad418c85..b5b521152e2 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt @@ -237,7 +237,7 @@ fun definePackageAlias(name: String, varName: JsName, tag: String, parentRef: Js val PsiElement.finalElement: PsiElement get() = when (this) { is KtFunctionLiteral -> rBrace ?: this - is KtDeclarationWithBody -> (bodyExpression as? KtBlockExpression)?.rBrace ?: bodyExpression ?: this + is KtDeclarationWithBody -> bodyBlockExpression?.rBrace ?: bodyExpression ?: this is KtLambdaExpression -> bodyExpression?.rBrace ?: this else -> this }