FIR IDE: don't add return for when expressions when converting to block
There doesn't seem to be a good reason why FE1.0 does this. Hence we won't do it in FIR.
This commit is contained in:
committed by
TeamCityServer
parent
55e7cc7ea3
commit
5a1223e812
+1
-6
@@ -17,8 +17,6 @@ import org.jetbrains.kotlin.idea.fir.applicators.ApplicabilityRanges
|
||||
import org.jetbrains.kotlin.idea.formatter.adjustLineIndent
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtClassErrorType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.idea.util.resultingWhens
|
||||
import org.jetbrains.kotlin.idea.util.setType
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -29,7 +27,6 @@ class HLConvertToBlockBodyIntention :
|
||||
AbstractHLIntention<KtDeclarationWithBody, HLConvertToBlockBodyIntention.Input>(KtDeclarationWithBody::class, applicator) {
|
||||
|
||||
class Input(
|
||||
val returnType: KtType,
|
||||
val returnTypeIsUnit: Boolean,
|
||||
val returnTypeIsNothing: Boolean,
|
||||
val returnTypeString: String,
|
||||
@@ -58,7 +55,6 @@ class HLConvertToBlockBodyIntention :
|
||||
val returnType = declaration.getReturnKtType().approximateToSuperPublicDenotableOrSelf()
|
||||
val bodyType = body.getKtType()
|
||||
return Input(
|
||||
returnType,
|
||||
returnType.isUnit,
|
||||
returnType.isNothing,
|
||||
returnType.render(),
|
||||
@@ -104,9 +100,8 @@ class HLConvertToBlockBodyIntention :
|
||||
private fun generateBody(body: KtExpression, input: Input, returnsValue: Boolean): KtExpression {
|
||||
val factory = KtPsiFactory(body)
|
||||
if (input.bodyTypeIsUnit && body is KtNameReferenceExpression) return factory.createEmptyBody()
|
||||
val unitWhenAsResult = input.bodyTypeIsUnit && body.resultingWhens().isNotEmpty()
|
||||
val needReturn = returnsValue && (!input.bodyTypeIsUnit && !input.bodyTypeIsNothing)
|
||||
return if (needReturn || unitWhenAsResult) {
|
||||
return if (needReturn) {
|
||||
val annotatedExpr = body as? KtAnnotatedExpression
|
||||
val returnedExpr = annotatedExpr?.baseExpression ?: body
|
||||
val block = factory.createSingleStatementBlock(factory.createExpressionByPattern("return $0", returnedExpr))
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
enum class AccessMode { READ, WRITE, EXECUTE }
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun whenExpr(access: AccessMode, arg: Boolean) {
|
||||
if (arg) {} else {
|
||||
foo()
|
||||
when (access) {
|
||||
AccessMode.READ -> {}
|
||||
AccessMode.WRITE -> {}
|
||||
AccessMode.EXECUTE -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
enum class AccessMode { READ, WRITE, EXECUTE }
|
||||
|
||||
fun whenExpr(access: AccessMode) {
|
||||
when (access) {
|
||||
AccessMode.READ -> {}
|
||||
AccessMode.WRITE -> {}
|
||||
AccessMode.EXECUTE -> {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user