提交 6dd331d7 编写于 作者: D Dmitriy Novozhilov

[FIR] Add tests for non exhaustive when as last expression of lambda

KT-44810
上级 e54f31cc
......@@ -1274,6 +1274,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
public void testMissingSealedInheritor() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingSealedInheritor.kt");
}
@TestMetadata("nonExhaustiveWhenWithoutCoercionToUnit.kt")
public void testNonExhaustiveWhenWithoutCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt");
}
}
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive")
......@@ -1327,6 +1332,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
public void testExhaustiveness_sealedSubClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt");
}
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt");
}
}
}
......
FILE: nonExhaustiveWhenWithoutCoercionToUnit.kt
public final fun <T> run(block: R|() -> T|): R|T| {
^run R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun test(a: R|kotlin/Any|): R|kotlin/Unit| {
R|/run|<R|kotlin/Unit|>(<L> = run@fun <anonymous>(): R|kotlin/Unit| {
when (R|<local>/a|) {
($subj$ is R|kotlin/String|) -> {
Int(1)
}
}
}
)
}
fun <T> run(block: () -> T): T = block()
fun test(a: Any) {
run {
// Should be an error, see KT-44810
when (a) {
is String -> 1
}
}
}
FILE: nonExhaustiveWhenWithCoercionToUnit.kt
public final fun <T> run(block: R|() -> T|): R|T| {
^run R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun test(a: R|kotlin/Any|, b: R|kotlin/Boolean|): R|kotlin/Unit| {
R|/run|<R|kotlin/Unit|>(<L> = run@fun <anonymous>(): R|kotlin/Unit| {
when () {
R|<local>/b| -> {
^@run Unit
}
}
when (R|<local>/a|) {
($subj$ is R|kotlin/String|) -> {
Int(1)
}
}
}
)
}
fun <T> run(block: () -> T): T = block()
fun test(a: Any, b: Boolean) {
run {
if (b) return@run
when (a) {
is String -> 1
}
}
}
......@@ -1459,6 +1459,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
public void testMissingSealedInheritor() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingSealedInheritor.kt");
}
@Test
@TestMetadata("nonExhaustiveWhenWithoutCoercionToUnit.kt")
public void testNonExhaustiveWhenWithoutCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt");
}
}
@Nested
......@@ -1517,6 +1523,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
public void testExhaustiveness_sealedSubClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt");
}
@Test
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt");
}
}
}
......
......@@ -1473,6 +1473,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
public void testMissingSealedInheritor() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingSealedInheritor.kt");
}
@Test
@TestMetadata("nonExhaustiveWhenWithoutCoercionToUnit.kt")
public void testNonExhaustiveWhenWithoutCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt");
}
}
@Nested
......@@ -1532,6 +1538,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
public void testExhaustiveness_sealedSubClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt");
}
@Test
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt");
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册