[AA] KtExpressionInfoProvider.getMissingCases: fix no subject case
return missing else branch (even if it's present, see kdoc) ^ KT-62875 fixed
This commit is contained in:
+18
@@ -58,6 +58,24 @@ public class Fe10IdeNormalAnalysisSourceModuleWhenMissingCasesTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_empty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject.kt")
|
||||
public void testBoolean_noSubject() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubjectIncorrectCode.kt")
|
||||
public void testBoolean_noSubjectIncorrectCode() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubjectIncorrectCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject_else.kt")
|
||||
public void testBoolean_noSubject_else() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject_else.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_partial.kt")
|
||||
public void testBoolean_partial() throws Exception {
|
||||
|
||||
+18
@@ -58,6 +58,24 @@ public class FirIdeDependentAnalysisSourceModuleWhenMissingCasesTestGenerated ex
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_empty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject.kt")
|
||||
public void testBoolean_noSubject() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubjectIncorrectCode.kt")
|
||||
public void testBoolean_noSubjectIncorrectCode() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubjectIncorrectCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject_else.kt")
|
||||
public void testBoolean_noSubject_else() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject_else.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_partial.kt")
|
||||
public void testBoolean_partial() throws Exception {
|
||||
|
||||
+18
@@ -58,6 +58,24 @@ public class FirIdeNormalAnalysisSourceModuleWhenMissingCasesTestGenerated exten
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_empty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject.kt")
|
||||
public void testBoolean_noSubject() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubjectIncorrectCode.kt")
|
||||
public void testBoolean_noSubjectIncorrectCode() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubjectIncorrectCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject_else.kt")
|
||||
public void testBoolean_noSubject_else() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject_else.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_partial.kt")
|
||||
public void testBoolean_partial() throws Exception {
|
||||
|
||||
+18
@@ -58,6 +58,24 @@ public class FirStandaloneNormalAnalysisSourceModuleWhenMissingCasesTestGenerate
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_empty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject.kt")
|
||||
public void testBoolean_noSubject() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubjectIncorrectCode.kt")
|
||||
public void testBoolean_noSubjectIncorrectCode() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubjectIncorrectCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_noSubject_else.kt")
|
||||
public void testBoolean_noSubject_else() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionInfoProvider/whenMissingCases/boolean_noSubject_else.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boolean_partial.kt")
|
||||
public void testBoolean_partial() throws Exception {
|
||||
|
||||
+9
@@ -36,6 +36,15 @@ public interface KtExpressionInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* else -> 3
|
||||
* }
|
||||
*
|
||||
* If when-expression has no subject, then else-branch would be reported as missing even if it is explicitly present:
|
||||
*
|
||||
* fun test() {
|
||||
* when {
|
||||
* true -> {}
|
||||
* else -> {}
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Note that this function returns the same missing cases regardless of the existence of the else branch.
|
||||
* If you have to assume that it does not have the missing cases when it has an else branch,
|
||||
* you need a separate check whether it has an else branch or not.
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
<caret>when {
|
||||
true -> {}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Unknown - else
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
<caret>when() {
|
||||
true -> {}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Unknown - else
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
<caret>when {
|
||||
true -> {}
|
||||
else -> { }
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Unknown - else
|
||||
+3
-1
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.enumWhenTracker
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.ExhaustivenessStatus.NotExhaustive
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirElseIfTrueCondition
|
||||
import org.jetbrains.kotlin.fir.reportEnumUsageInWhen
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
@@ -43,7 +44,8 @@ class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyRe
|
||||
)
|
||||
|
||||
fun computeAllMissingCases(session: FirSession, whenExpression: FirWhenExpression): List<WhenMissingCase> {
|
||||
val subjectType = getSubjectType(session, whenExpression) ?: return emptyList()
|
||||
val subjectType =
|
||||
getSubjectType(session, whenExpression) ?: return NotExhaustive.NO_ELSE_BRANCH.reasons
|
||||
return buildList {
|
||||
for (type in subjectType.unwrapIntersectionType()) {
|
||||
val checkers = getCheckers(type, session)
|
||||
|
||||
Reference in New Issue
Block a user