Add test for smart cast on a value bound to when subject variable
E.g.:
when (val y = x?.foo()) {
null -> ...
else -> ... // 'x' is also non-null here
}
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
||||
|
||||
fun foo(s1: String, s2: String) = s1 + s2
|
||||
|
||||
fun test(x: Any?) =
|
||||
when (val y = x?.toString()) {
|
||||
null -> "null"
|
||||
else -> foo(<!DEBUG_INFO_SMARTCAST!>x<!>.toString(), <!DEBUG_INFO_SMARTCAST!>y<!>)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ s1: kotlin.String, /*1*/ s2: kotlin.String): kotlin.String
|
||||
public fun test(/*0*/ x: kotlin.Any?): kotlin.String
|
||||
@@ -22484,6 +22484,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastOnValueBoundToSubjectVariable.kt")
|
||||
public void testSmartCastOnValueBoundToSubjectVariable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastsOnSubjectVariable.kt")
|
||||
public void testSmartCastsOnSubjectVariable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastsOnSubjectVariable.kt");
|
||||
|
||||
Generated
+6
@@ -22484,6 +22484,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastOnValueBoundToSubjectVariable.kt")
|
||||
public void testSmartCastOnValueBoundToSubjectVariable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastsOnSubjectVariable.kt")
|
||||
public void testSmartCastsOnSubjectVariable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastsOnSubjectVariable.kt");
|
||||
|
||||
Reference in New Issue
Block a user