CFG: provide "used as expression" in enum constant constructor
This allows to avoid "unused return value of a function with lambda expression body" for such a situation So #KT-20429 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e10fa218f5
commit
a65304556c
@@ -1447,6 +1447,14 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
generateCallOrMarkUnresolved(call)
|
||||
}
|
||||
|
||||
override fun visitInitializerList(list: KtInitializerList) {
|
||||
list.initializers
|
||||
.filterIsInstance<KtSuperTypeCallEntry>()
|
||||
.forEach {
|
||||
generateCallOrMarkUnresolved(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateCallOrMarkUnresolved(call: KtCallElement) {
|
||||
if (!generateCall(call)) {
|
||||
val arguments = call.valueArguments.mapNotNull(ValueArgument::getArgumentExpression)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.UnusedLambdaExpressionBodyInspection
|
||||
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
|
||||
enum class Test(f: () -> Unit) {
|
||||
A(<caret>getFunc())
|
||||
}
|
||||
|
||||
fun getFunc(): () -> Unit = {}
|
||||
@@ -3861,6 +3861,21 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class UnusedLambdaExpressionBody extends AbstractLocalInspectionTest {
|
||||
public void testAllFilesPresentInUnusedLambdaExpressionBody() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/unusedLambdaExpressionBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inEnumEntry.kt")
|
||||
public void testInEnumEntry() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody/inEnumEntry.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/unusedReceiverParameter")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user