diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.kt new file mode 100644 index 00000000000..903af22d07e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.kt @@ -0,0 +1,10 @@ +class User(val login : Boolean) {} + +fun currentAccess(user: User?): Int { + return when { + user == null -> 0 + // We should get smartcast here + user.login -> 1 + else -> -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.txt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.txt new file mode 100644 index 00000000000..f87f8016e7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.txt @@ -0,0 +1,11 @@ +package + +internal fun currentAccess(/*0*/ user: User?): kotlin.Int + +internal final class User { + public constructor User(/*0*/ login: kotlin.Boolean) + internal final val login: kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.kt new file mode 100644 index 00000000000..b1380b47ff9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.kt @@ -0,0 +1,5 @@ +fun foo(p: String?): Int { + // We should get smart cast here + val x = if (p != null) { p } else "a" + return x.length() +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.txt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.txt new file mode 100644 index 00000000000..5b4d1cea87d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.txt @@ -0,0 +1,3 @@ +package + +internal fun foo(/*0*/ p: kotlin.String?): kotlin.Int diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 7a0c5f78191..74273ef51c2 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -11187,12 +11187,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/varnotnull"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("kt3993.kt") + public void testKt3993() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt3993.kt"); + doTest(fileName); + } + @TestMetadata("kt4409.kt") public void testKt4409() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt4409.kt"); doTest(fileName); } + @TestMetadata("kt5427.kt") + public void testKt5427() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5427.kt"); + doTest(fileName); + } + @TestMetadata("kt5907.kt") public void testKt5907() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5907.kt");