[FIR] Try to infer result type of incomplete when expression
^KT-62069 Fixed
This commit is contained in:
committed by
Space Team
parent
e2f245096c
commit
88f7b085e6
+6
@@ -8542,6 +8542,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/nestedLoopsWithMultipleLabels.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noTypeMismatchWithWhenWithoutElse.kt")
|
||||
public void testNoTypeMismatchWithWhenWithoutElse() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/noTypeMismatchWithWhenWithoutElse.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nonExhaustiveIfInElvis_after.kt")
|
||||
public void testNonExhaustiveIfInElvis_after() throws Exception {
|
||||
|
||||
+6
@@ -8542,6 +8542,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/nestedLoopsWithMultipleLabels.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noTypeMismatchWithWhenWithoutElse.kt")
|
||||
public void testNoTypeMismatchWithWhenWithoutElse() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/noTypeMismatchWithWhenWithoutElse.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nonExhaustiveIfInElvis_after.kt")
|
||||
public void testNonExhaustiveIfInElvis_after() throws Exception {
|
||||
|
||||
Vendored
+3
-3
@@ -1,12 +1,12 @@
|
||||
FILE: missingBooleanBranch.kt
|
||||
public final fun test_1(cond: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/cond|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/cond|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
lval y: R|kotlin/Unit| = when (R|<local>/cond|) {
|
||||
lval y: R|kotlin/Int| = when (R|<local>/cond|) {
|
||||
==($subj$, Boolean(false)) -> {
|
||||
Int(2)
|
||||
}
|
||||
@@ -23,7 +23,7 @@ FILE: missingBooleanBranch.kt
|
||||
|
||||
}
|
||||
public final fun test_2(cond: R|kotlin/Boolean?|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/cond|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/cond|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: missingElse.kt
|
||||
public final fun test(a: R|kotlin/Any|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/a|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/a|) {
|
||||
($subj$ is R|kotlin/Int|) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -17,7 +17,7 @@ FILE: missingEnumEntry.kt
|
||||
|
||||
}
|
||||
public final fun test_1(enum: R|SomeEnum|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/enum|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/enum|) {
|
||||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ FILE: missingEnumEntry.kt
|
||||
|
||||
}
|
||||
public final fun test_2(enum: R|SomeEnum?|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/enum|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/enum|) {
|
||||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -20,13 +20,13 @@ FILE: b.kt
|
||||
}
|
||||
FILE: c.kt
|
||||
public final fun test_1(base: R|Base|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/base|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/base|) {
|
||||
($subj$ is R|A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
lval y: R|kotlin/Unit| = when (R|<local>/base|) {
|
||||
lval y: R|kotlin/Int| = when (R|<local>/base|) {
|
||||
==($subj$, Q|B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ FILE: c.kt
|
||||
|
||||
}
|
||||
public final fun test_2(base: R|Base?|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/base|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/base|) {
|
||||
($subj$ is R|A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ FILE: c.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval y: R|kotlin/Unit| = when (R|<local>/base|) {
|
||||
lval y: R|kotlin/Int| = when (R|<local>/base|) {
|
||||
($subj$ is R|A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
FILE: exhaustiveness_boolean.kt
|
||||
public final fun test_1(b: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/b|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ FILE: exhaustiveness_boolean.kt
|
||||
|
||||
}
|
||||
public final fun test_2(b: R|kotlin/Boolean?|): R|kotlin/Unit| {
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/b|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -18,7 +18,7 @@ FILE: exhaustiveness_enum.kt
|
||||
|
||||
}
|
||||
public final fun test_1(e: R|Enum|): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Unit| = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|Enum|.R|/Enum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ FILE: exhaustiveness_enum.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval b: R|kotlin/Unit| = when (R|<local>/e|) {
|
||||
lval b: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|Enum|.R|/Enum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ FILE: exhaustiveness_enum.kt
|
||||
|
||||
}
|
||||
public final fun test_2(e: R|Enum?|): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Unit| = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|Enum|.R|/Enum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enumJava.fir.txt
Vendored
+6
-6
@@ -1,6 +1,6 @@
|
||||
FILE: main.kt
|
||||
public final fun test_1(e: R|JavaEnum|): R|kotlin/Unit| {
|
||||
lval a: <ERROR TYPE REF: Unresolved name: plus> = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|JavaEnum|.R|/JavaEnum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -8,8 +8,8 @@ FILE: main.kt
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
.<Unresolved name: plus>#(Int(0))
|
||||
lval b: <ERROR TYPE REF: Unresolved name: plus> = when (R|<local>/e|) {
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
lval b: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|JavaEnum|.R|/JavaEnum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -20,7 +20,7 @@ FILE: main.kt
|
||||
Int(3)
|
||||
}
|
||||
}
|
||||
.<Unresolved name: plus>#(Int(0))
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
lval c: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|JavaEnum|.R|/JavaEnum.A|) -> {
|
||||
Int(1)
|
||||
@@ -44,7 +44,7 @@ FILE: main.kt
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
}
|
||||
public final fun test_2(e: R|JavaEnum?|): R|kotlin/Unit| {
|
||||
lval a: <ERROR TYPE REF: Unresolved name: plus> = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|JavaEnum|.R|/JavaEnum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ FILE: main.kt
|
||||
Int(3)
|
||||
}
|
||||
}
|
||||
.<Unresolved name: plus>#(Int(0))
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
lval b: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
==($subj$, Q|JavaEnum|.R|/JavaEnum.A|) -> {
|
||||
Int(1)
|
||||
|
||||
Vendored
+3
-3
@@ -10,13 +10,13 @@ fun test_1(e: JavaEnum) {
|
||||
val a = <!NO_ELSE_IN_WHEN!>when<!> (e) {
|
||||
JavaEnum.A -> 1
|
||||
JavaEnum.B -> 2
|
||||
}.<!UNRESOLVED_REFERENCE!>plus<!>(0)
|
||||
}.plus(0)
|
||||
|
||||
val b = <!NO_ELSE_IN_WHEN!>when<!> (e) {
|
||||
JavaEnum.A -> 1
|
||||
JavaEnum.B -> 2
|
||||
is String -> 3
|
||||
}.<!UNRESOLVED_REFERENCE!>plus<!>(0)
|
||||
}.plus(0)
|
||||
|
||||
val c = when (e) {
|
||||
JavaEnum.A -> 1
|
||||
@@ -35,7 +35,7 @@ fun test_2(e: JavaEnum?) {
|
||||
JavaEnum.A -> 1
|
||||
JavaEnum.B -> 2
|
||||
JavaEnum.C -> 3
|
||||
}.<!UNRESOLVED_REFERENCE!>plus<!>(0)
|
||||
}.plus(0)
|
||||
|
||||
val b = when (e) {
|
||||
JavaEnum.A -> 1
|
||||
|
||||
+3
-3
@@ -26,7 +26,7 @@ FILE: exhaustiveness_sealedClass.kt
|
||||
|
||||
}
|
||||
public final fun test_1(e: R|Base|): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Unit| = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|Base.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ FILE: exhaustiveness_sealedClass.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval b: R|kotlin/Unit| = when (R|<local>/e|) {
|
||||
lval b: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|Base.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -70,7 +70,7 @@ FILE: exhaustiveness_sealedClass.kt
|
||||
|
||||
}
|
||||
public final fun test_2(e: R|Base?|): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Unit| = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|Base.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
+6
-6
@@ -77,7 +77,7 @@ FILE: exhaustiveness_sealedSubClass.kt
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
}
|
||||
public final fun test_2(e: R|A|): R|kotlin/Unit| {
|
||||
lval a: <ERROR TYPE REF: Unresolved name: plus> = when (R|<local>/e|) {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|D|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -85,8 +85,8 @@ FILE: exhaustiveness_sealedSubClass.kt
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
.<Unresolved name: plus>#(Int(0))
|
||||
lval b: <ERROR TYPE REF: Unresolved name: plus> = when (R|<local>/e|) {
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
lval b: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -97,8 +97,8 @@ FILE: exhaustiveness_sealedSubClass.kt
|
||||
Int(3)
|
||||
}
|
||||
}
|
||||
.<Unresolved name: plus>#(Int(0))
|
||||
lval c: <ERROR TYPE REF: Unresolved name: plus> = when (R|<local>/e|) {
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
lval c: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ FILE: exhaustiveness_sealedSubClass.kt
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
.<Unresolved name: plus>#(Int(0))
|
||||
.R|kotlin/Int.plus|(Int(0))
|
||||
lval d: R|kotlin/Int| = when (R|<local>/e|) {
|
||||
($subj$ is R|C|) -> {
|
||||
Int(1)
|
||||
|
||||
+3
-3
@@ -35,18 +35,18 @@ fun test_2(e: A) {
|
||||
val a = <!NO_ELSE_IN_WHEN!>when<!> (e) {
|
||||
is D -> 1
|
||||
is E -> 2
|
||||
}.<!UNRESOLVED_REFERENCE!>plus<!>(0)
|
||||
}.plus(0)
|
||||
|
||||
val b = <!NO_ELSE_IN_WHEN!>when<!> (e) {
|
||||
is B -> 1
|
||||
is D -> 2
|
||||
is E -> 3
|
||||
}.<!UNRESOLVED_REFERENCE!>plus<!>(0)
|
||||
}.plus(0)
|
||||
|
||||
val c = <!NO_ELSE_IN_WHEN!>when<!> (e) {
|
||||
is B -> 1
|
||||
is D -> 2
|
||||
}.<!UNRESOLVED_REFERENCE!>plus<!>(0)
|
||||
}.plus(0)
|
||||
|
||||
val d = when (e) {
|
||||
is C -> 1
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
FILE: exhaustiveness_smartcastedBoolean.kt
|
||||
public final fun test_1(b: R|kotlin/Any|): R|kotlin/Unit| {
|
||||
R|kotlin/require|((R|<local>/b| is R|kotlin/Boolean|))
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/b|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
@@ -28,7 +28,7 @@ FILE: exhaustiveness_smartcastedBoolean.kt
|
||||
}
|
||||
public final fun test_2(b: R|kotlin/Any?|): R|kotlin/Unit| {
|
||||
R|kotlin/require|((R|<local>/b| is R|kotlin/Boolean?|))
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/b|) {
|
||||
lval x: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -16,7 +16,7 @@ FILE: enumWithTheSameNameAsEntry.kt
|
||||
public get(): R|kotlin/enums/EnumEntries<A>|
|
||||
|
||||
}
|
||||
public final fun test(a: R|A|): R|kotlin/Unit| {
|
||||
public final fun test(a: R|A|): R|kotlin/String| {
|
||||
^test when (R|<local>/a|) {
|
||||
==($subj$, R|/A.A|.<Unresolved name: A>#) -> {
|
||||
String(A)
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
FILE: test.kt
|
||||
public final fun foo(javaEnum: R|JavaEnum|): R|kotlin/Unit| {
|
||||
public final fun foo(javaEnum: R|JavaEnum|): R|kotlin/Int| {
|
||||
^foo when (R|<local>/javaEnum|) {
|
||||
==($subj$, <Unresolved name: first>#()) -> {
|
||||
Int(1)
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ FILE: second.kt
|
||||
}
|
||||
public final val ONE: R|second/Second| = Q|second/Second|.R|second/Second.THREE|
|
||||
public get(): R|second/Second|
|
||||
public final fun foo(f: R|first/First|): R|kotlin/Unit| {
|
||||
public final fun foo(f: R|first/First|): R|kotlin/Int| {
|
||||
^foo when (R|<local>/f|) {
|
||||
==($subj$, R|second/ONE|) -> {
|
||||
Int(1)
|
||||
@@ -53,7 +53,7 @@ FILE: second.kt
|
||||
}
|
||||
|
||||
}
|
||||
public final fun bar(s: R|second/Second|): R|kotlin/Unit| {
|
||||
public final fun bar(s: R|second/Second|): R|kotlin/Int| {
|
||||
^bar when (R|<local>/s|) {
|
||||
==($subj$, R|first/THREE|) -> {
|
||||
Int(3)
|
||||
|
||||
@@ -44,7 +44,7 @@ FILE: whenElse.kt
|
||||
}
|
||||
public final fun case2(): R|kotlin/Unit| {
|
||||
lval flag: R|kotlin/Any| = R|/get|(Boolean(false))
|
||||
lval l1: R|kotlin/Unit| = when (R|<local>/flag|!!) {
|
||||
lval l1: R|B| = when (R|<local>/flag|!!) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
@@ -53,7 +53,7 @@ FILE: whenElse.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval l2: R|kotlin/Unit| = when (R|<local>/flag|) {
|
||||
lval l2: R|B| = when (R|<local>/flag|) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
@@ -65,7 +65,7 @@ FILE: whenElse.kt
|
||||
}
|
||||
public final fun case2(): R|kotlin/Unit| {
|
||||
lval flag: R|kotlin/Any| = R|/get|(Boolean(true))
|
||||
lval l1: R|kotlin/Unit| = when (R|<local>/flag|!!) {
|
||||
lval l1: R|B| = when (R|<local>/flag|!!) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
@@ -74,7 +74,7 @@ FILE: whenElse.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval l2: R|kotlin/Unit| = when (R|<local>/flag|) {
|
||||
lval l2: R|B| = when (R|<local>/flag|) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
@@ -86,7 +86,7 @@ FILE: whenElse.kt
|
||||
}
|
||||
public final fun case3(): R|kotlin/Unit| {
|
||||
lval flag: R|kotlin/String| = String()
|
||||
lval l1: R|kotlin/Unit| = when (R|<local>/flag|!!) {
|
||||
lval l1: R|B| = when (R|<local>/flag|!!) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
@@ -95,7 +95,7 @@ FILE: whenElse.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval l2: R|kotlin/Unit| = when (R|<local>/flag|) {
|
||||
lval l2: R|B| = when (R|<local>/flag|) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ FILE: whenExpressionType.kt
|
||||
}
|
||||
public final fun case9(): R|kotlin/Unit| {
|
||||
lval flag: R|kotlin/Any| = Q|A|.R|/A.A1|
|
||||
lval l1: R|kotlin/Unit| = when (R|<local>/flag|) {
|
||||
lval l1: R|B| = when (R|<local>/flag|) {
|
||||
==($subj$, Q|A|.R|/A.A1|) -> {
|
||||
R|/B.B|()
|
||||
}
|
||||
@@ -158,5 +158,5 @@ FILE: whenExpressionType.kt
|
||||
}
|
||||
}
|
||||
|
||||
lval x1: R|C| = R|/C.C<Inapplicable(INAPPLICABLE): /C.C>#|(R|<local>/l1|)
|
||||
lval x1: R|C| = R|/C.C|(R|<local>/l1|)
|
||||
}
|
||||
|
||||
@@ -106,6 +106,6 @@ fun case9() {
|
||||
A.A1 -> B()
|
||||
A.A2 -> B()
|
||||
}
|
||||
val x1 = C(<!ARGUMENT_TYPE_MISMATCH!>l1<!>)
|
||||
val x1 = C(l1)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -8536,6 +8536,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/nestedLoopsWithMultipleLabels.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noTypeMismatchWithWhenWithoutElse.kt")
|
||||
public void testNoTypeMismatchWithWhenWithoutElse() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/noTypeMismatchWithWhenWithoutElse.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nonExhaustiveIfInElvis_after.kt")
|
||||
public void testNonExhaustiveIfInElvis_after() throws Exception {
|
||||
|
||||
+6
@@ -8542,6 +8542,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/nestedLoopsWithMultipleLabels.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noTypeMismatchWithWhenWithoutElse.kt")
|
||||
public void testNoTypeMismatchWithWhenWithoutElse() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/noTypeMismatchWithWhenWithoutElse.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nonExhaustiveIfInElvis_after.kt")
|
||||
public void testNonExhaustiveIfInElvis_after() throws Exception {
|
||||
|
||||
+4
-2
@@ -68,7 +68,9 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
|
||||
var completionNeeded = false
|
||||
context.withWhenSubjectType(subjectType, components) {
|
||||
when {
|
||||
whenExpression.branches.isEmpty() -> {}
|
||||
whenExpression.branches.isEmpty() -> {
|
||||
whenExpression.resultType = session.builtinTypes.unitType.type
|
||||
}
|
||||
whenExpression.isOneBranch() && data.forceFullCompletion && data !is ResolutionMode.WithExpectedType -> {
|
||||
whenExpression = whenExpression.transformBranches(transformer, ResolutionMode.ContextIndependent)
|
||||
whenExpression.resultType = whenExpression.branches.first().result.resolvedType
|
||||
@@ -115,7 +117,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
|
||||
}
|
||||
|
||||
private fun FirWhenExpression.replaceReturnTypeIfNotExhaustive(): FirWhenExpression {
|
||||
if (!isProperlyExhaustive) {
|
||||
if (!isProperlyExhaustive && !usedAsExpression) {
|
||||
resultType = session.builtinTypes.unitType.type
|
||||
}
|
||||
return this
|
||||
|
||||
+5
-5
@@ -11,18 +11,18 @@ val mlist = MList()
|
||||
fun work() {}
|
||||
|
||||
val xx1 = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
val xx2: Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
val xx2: Unit = <!INITIALIZER_TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42<!>
|
||||
val xx3 = idAny(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
|
||||
val xx4 = id(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
|
||||
val xx5 = idUnit(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
|
||||
val xx5 = idUnit(<!ARGUMENT_TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42<!>)
|
||||
val xx6 = null ?: <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
val xx7 = "" + <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
|
||||
val wxx1 = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
val wxx2: Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
val wxx2: Unit = <!INITIALIZER_TYPE_MISMATCH!><!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }<!>
|
||||
val wxx3 = idAny(<!NO_ELSE_IN_WHEN!>when<!> { true -> 42 })
|
||||
val wxx4 = id(<!NO_ELSE_IN_WHEN!>when<!> { true -> 42 })
|
||||
val wxx5 = idUnit(<!NO_ELSE_IN_WHEN!>when<!> { true -> 42 })
|
||||
val wxx5 = idUnit(<!ARGUMENT_TYPE_MISMATCH!><!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }<!>)
|
||||
val wxx6 = null ?: <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
val wxx7 = "" + <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
|
||||
@@ -57,7 +57,7 @@ fun foo1(x: String?) {
|
||||
"" + <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
w@while (true) {
|
||||
x ?: <!INVALID_IF_AS_EXPRESSION!>if<!> (true) break
|
||||
x ?: <!NO_ELSE_IN_WHEN!>when<!> { true -> break@w }
|
||||
x <!USELESS_ELVIS!>?: <!NO_ELSE_IN_WHEN!>when<!> { true -> break@w }<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// ISSUE: KT-62069
|
||||
|
||||
enum class ExhaustiveEnum { ONE, TWO }
|
||||
|
||||
fun exhaust(ee: ExhaustiveEnum) {
|
||||
var v = 0
|
||||
v = <!NO_ELSE_IN_WHEN!>when<!> (ee) {
|
||||
ExhaustiveEnum.ONE -> 1
|
||||
}
|
||||
v = <!INVALID_IF_AS_EXPRESSION!>if<!> (ee == ExhaustiveEnum.ONE) 2
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// ISSUE: KT-62069
|
||||
|
||||
enum class ExhaustiveEnum { ONE, TWO }
|
||||
|
||||
fun exhaust(ee: ExhaustiveEnum) {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>v<!> = 0
|
||||
v = <!NO_ELSE_IN_WHEN!>when<!> (ee) {
|
||||
ExhaustiveEnum.ONE -> 1
|
||||
}
|
||||
v = <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (ee == ExhaustiveEnum.ONE) 2<!>
|
||||
}
|
||||
+1
-1
@@ -38,5 +38,5 @@ fun foo(a: A) {
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (a) {
|
||||
is A.A1 -> ""
|
||||
is B.B1 -> "..."
|
||||
}.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}.length
|
||||
}
|
||||
|
||||
Generated
+6
@@ -8542,6 +8542,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/nestedLoopsWithMultipleLabels.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noTypeMismatchWithWhenWithoutElse.kt")
|
||||
public void testNoTypeMismatchWithWhenWithoutElse() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlStructures/noTypeMismatchWithWhenWithoutElse.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nonExhaustiveIfInElvis_after.kt")
|
||||
public void testNonExhaustiveIfInElvis_after() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user