[kotlin k2] AddReturnExpressionFix: do not suggest a quick fix if there is no right bracket

^KTIJ-29554

GitOrigin-RevId: aa9488718babe674febfeb7cff83ddefc9a60442
This commit is contained in:
Andrey Cherkasov
2024-06-03 16:28:25 +00:00
committed by intellij-monorepo-bot
parent 8bfc8aedb8
commit ffda2a4aae
4 changed files with 15 additions and 0 deletions
@@ -10,6 +10,7 @@ internal object AddReturnExpressionFixFactory {
val addReturnExpressionFixFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.NoReturnInFunctionWithBlockBody ->
val function = (diagnostic.psi as? KtNamedFunction) ?: return@ModCommandBased emptyList()
if (function.bodyBlockExpression?.rBrace == null) return@ModCommandBased emptyList()
listOf(
AddReturnExpressionFix(function)
@@ -5257,6 +5257,11 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
runTest("../../../idea/tests/testData/quickfix/addReturnExpression/emptyBody.kt");
}
@TestMetadata("noRightBrace.kt")
public void testNoRightBrace() throws Exception {
runTest("../../../idea/tests/testData/quickfix/addReturnExpression/noRightBrace.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("../../../idea/tests/testData/quickfix/addReturnExpression/simple.kt");
@@ -1599,6 +1599,11 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
runTest("testData/quickfix/addReturnExpression/emptyBody.kt");
}
@TestMetadata("noRightBrace.kt")
public void testNoRightBrace() throws Exception {
runTest("testData/quickfix/addReturnExpression/noRightBrace.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("testData/quickfix/addReturnExpression/simple.kt");
@@ -0,0 +1,4 @@
// "Add 'return' expression" "false"
// ERROR: A 'return' expression required in a function with a block body ('{...}')
fun test(): Boolean {<caret>
val x = 42