[FE 1.0] Fix false-negative INVALID_IF_AS_EXPRESSION_WARNING and NO_ELSE_IN_WHEN_WARNING
^KT-51711 Fixed
This commit is contained in:
committed by
teamcity
parent
c67c1a69b9
commit
565c61a702
+6
@@ -6386,6 +6386,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt4310.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51711.kt")
|
||||
public void testKt51711() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt51711.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt657.kt")
|
||||
public void testKt657() throws Exception {
|
||||
|
||||
+6
@@ -6386,6 +6386,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt4310.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51711.kt")
|
||||
public void testKt51711() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt51711.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt657.kt")
|
||||
public void testKt657() throws Exception {
|
||||
|
||||
+6
@@ -6386,6 +6386,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt4310.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51711.kt")
|
||||
public void testKt51711() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt51711.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt657.kt")
|
||||
public void testKt657() throws Exception {
|
||||
|
||||
+12
-8
@@ -955,20 +955,23 @@ class ControlFlowInformationProviderImpl private constructor(
|
||||
for (element in instruction.owner.getValueElements(value)) {
|
||||
if (element !is KtIfExpression) continue
|
||||
|
||||
if (element.isUsedAsExpression(trace.bindingContext)) {
|
||||
val thenExpression = element.then
|
||||
val elseExpression = element.`else`
|
||||
val thenExpression = element.then
|
||||
val elseExpression = element.`else`
|
||||
val isEhxaustive = thenExpression != null && elseExpression != null
|
||||
|
||||
if (thenExpression == null || elseExpression == null) {
|
||||
if (element.isUsedAsExpression(trace.bindingContext)) {
|
||||
if (!isEhxaustive) {
|
||||
trace.report(INVALID_IF_AS_EXPRESSION.on(element.ifKeyword))
|
||||
} else {
|
||||
checkImplicitCastOnConditionalExpression(element)
|
||||
}
|
||||
} else if (!languageVersionSettings.supportsFeature(LanguageFeature.ProhibitNonExhaustiveIfInRhsOfElvis)) {
|
||||
val parent = element.deparenthesizedParent
|
||||
if (parent is KtBinaryExpression) {
|
||||
if (parent.operationToken === KtTokens.ELVIS) {
|
||||
trace.report(INVALID_IF_AS_EXPRESSION_WARNING.on(element.getIfKeyword()))
|
||||
if (!isEhxaustive) {
|
||||
val parent = element.deparenthesizedParent
|
||||
if (parent is KtBinaryExpression) {
|
||||
if (parent.operationToken === KtTokens.ELVIS) {
|
||||
trace.report(INVALID_IF_AS_EXPRESSION_WARNING.on(element.getIfKeyword()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1067,6 +1070,7 @@ class ControlFlowInformationProviderImpl private constructor(
|
||||
if (
|
||||
!usedAsExpression &&
|
||||
missingCases.isNotEmpty() &&
|
||||
elseEntry == null &&
|
||||
!languageVersionSettings.supportsFeature(LanguageFeature.ProhibitNonExhaustiveIfInRhsOfElvis)
|
||||
) {
|
||||
val parent = element.deparenthesizedParent
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// FIR_IDENTICAL
|
||||
// LANGUAGE: -ProhibitNonExhaustiveIfInRhsOfElvis
|
||||
// ISSUE: KT-51711
|
||||
// WITH_STDLIB
|
||||
|
||||
private fun fake(a: String?) {}
|
||||
|
||||
fun test_1(x: String?, y: String?) {
|
||||
while (true) {
|
||||
x ?: if (y == null) break else fake(y)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun test_2(x: String?, y: String?) {
|
||||
while (true) {
|
||||
x ?: when {
|
||||
true -> break
|
||||
else -> y?.filter { it.isLowerCase() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
private fun fake(/*0*/ a: kotlin.String?): kotlin.Unit
|
||||
public fun test_1(/*0*/ x: kotlin.String?, /*1*/ y: kotlin.String?): kotlin.Unit
|
||||
public fun test_2(/*0*/ x: kotlin.String?, /*1*/ y: kotlin.String?): kotlin.Unit
|
||||
Generated
+6
@@ -6392,6 +6392,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt4310.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51711.kt")
|
||||
public void testKt51711() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/kt51711.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt657.kt")
|
||||
public void testKt657() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user