diff --git a/compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.kt b/compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.kt new file mode 100644 index 00000000000..21ab6befc9b --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.kt @@ -0,0 +1,10 @@ +fun Any.withInvoke(f: String.() -> Unit) { + if (this is String) { + f() // Should be OK + } +} + +fun String.withInvoke(f: String.() -> Unit) { + f() +} + diff --git a/compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.txt b/compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.txt new file mode 100644 index 00000000000..cb95e977c61 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.txt @@ -0,0 +1,12 @@ +FILE: invoke.kt + public final fun R|kotlin/Any|.withInvoke(f: R|kotlin/String.() -> kotlin/Unit|): R|kotlin/Unit| { + when () { + (this@R|/withInvoke| is R|kotlin/String|) -> { + #() + } + } + + } + public final fun R|kotlin/String|.withInvoke(f: R|kotlin/String.() -> kotlin/Unit|): R|kotlin/Unit| { + R|/f|.R|FakeOverride|(this@R|/withInvoke|) + } diff --git a/compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt b/compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt new file mode 100644 index 00000000000..1fb3e08bfe4 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt @@ -0,0 +1,14 @@ +fun takeString(s: String) {} + +class Wrapper(val s: String?) { + fun withThis() { + if (s != null) { + takeString(this.s) // Should be OK + } + if (this.s != null) { + takeString(s) // Should be OK + } + } +} + +fun takeString(s: String) {} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.txt b/compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.txt new file mode 100644 index 00000000000..e67c517edc3 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.txt @@ -0,0 +1,29 @@ +FILE: mixingImplicitAndExplicitReceivers.kt + public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| { + } + public final class Wrapper : R|kotlin/Any| { + public constructor(s: R|kotlin/String?|): R|Wrapper| { + super() + } + + public final val s: R|kotlin/String?| = R|/s| + public get(): R|kotlin/String?| + + public final fun withThis(): R|kotlin/Unit| { + when () { + !=(this@R|/Wrapper|.R|/Wrapper.s|, Null(null)) -> { + R|/takeString|(this@R|/Wrapper|.R|/Wrapper.s|) + } + } + + when () { + !=(this@R|/Wrapper|.R|/Wrapper.s|, Null(null)) -> { + R|/takeString|(this@R|/Wrapper|.R|/Wrapper.s|) + } + } + + } + + } + public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| { + } diff --git a/compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.kt b/compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.kt deleted file mode 100644 index c77ab4db826..00000000000 --- a/compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.kt +++ /dev/null @@ -1,30 +0,0 @@ -fun test_2(s: String?) { - s?.let { - takeString(it) // Should be OK - takeString(s) // Should be OK - } -} - -class Wrapper(val s: String?) { - fun withThis() { - if (s != null) { - takeString(this.s) // Should be OK - } - if (this.s != null) { - takeString(s) // Should be OK - } - } -} - -fun Any.withInvoke(f: String.() -> Unit) { - if (this is String) { - f() // Should be OK - } -} - -fun String.withInvoke(f: String.() -> Unit) { - f() -} - -fun takeString(s: String) {} - diff --git a/compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.txt b/compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.txt deleted file mode 100644 index 7d089d28cb7..00000000000 --- a/compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.txt +++ /dev/null @@ -1,45 +0,0 @@ -FILE: complexSmartCasts.kt - public final fun test_2(s: R|kotlin/String?|): R|kotlin/Unit| { - R|/s|?.R|kotlin/let|( = let@fun (it: R|kotlin/String|): R|kotlin/Unit| { - R|/takeString|(R|/it|) - R|/takeString|(R|/s|) - } - ) - } - public final class Wrapper : R|kotlin/Any| { - public constructor(s: R|kotlin/String?|): R|Wrapper| { - super() - } - - public final val s: R|kotlin/String?| = R|/s| - public get(): R|kotlin/String?| - - public final fun withThis(): R|kotlin/Unit| { - when () { - !=(this@R|/Wrapper|.R|/Wrapper.s|, Null(null)) -> { - R|/takeString|(this@R|/Wrapper|.R|/Wrapper.s|) - } - } - - when () { - !=(this@R|/Wrapper|.R|/Wrapper.s|, Null(null)) -> { - R|/takeString|(this@R|/Wrapper|.R|/Wrapper.s|) - } - } - - } - - } - public final fun R|kotlin/Any|.withInvoke(f: R|kotlin/String.() -> kotlin/Unit|): R|kotlin/Unit| { - when () { - (this@R|/withInvoke| is R|kotlin/String|) -> { - #() - } - } - - } - public final fun R|kotlin/String|.withInvoke(f: R|kotlin/String.() -> kotlin/Unit|): R|kotlin/Unit| { - R|/f|.R|FakeOverride|(this@R|/withInvoke|) - } - public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| { - } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 39fd8baaaa4..b61d2f16a76 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1581,6 +1581,24 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { } } + @TestMetadata("compiler/fir/resolve/testData/resolve/smartcasts/problems") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Problems extends AbstractFirDiagnosticsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInProblems() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/smartcasts/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.kt"); + } + } + @TestMetadata("compiler/fir/resolve/testData/resolve/smartcasts/receivers") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -1603,6 +1621,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/smartcasts/receivers/implicitReceivers.kt"); } + @TestMetadata("mixingImplicitAndExplicitReceivers.kt") + public void testMixingImplicitAndExplicitReceivers() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt"); + } + @TestMetadata("thisOfExtensionProperty.kt") public void testThisOfExtensionProperty() throws Exception { runTest("compiler/fir/resolve/testData/resolve/smartcasts/receivers/thisOfExtensionProperty.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index bfed775fda9..df51492ca08 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1581,6 +1581,24 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos } } + @TestMetadata("compiler/fir/resolve/testData/resolve/smartcasts/problems") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Problems extends AbstractFirDiagnosticsWithLightTreeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInProblems() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/smartcasts/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/smartcasts/problems/invoke.kt"); + } + } + @TestMetadata("compiler/fir/resolve/testData/resolve/smartcasts/receivers") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -1603,6 +1621,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/smartcasts/receivers/implicitReceivers.kt"); } + @TestMetadata("mixingImplicitAndExplicitReceivers.kt") + public void testMixingImplicitAndExplicitReceivers() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/smartcasts/receivers/mixingImplicitAndExplicitReceivers.kt"); + } + @TestMetadata("thisOfExtensionProperty.kt") public void testThisOfExtensionProperty() throws Exception { runTest("compiler/fir/resolve/testData/resolve/smartcasts/receivers/thisOfExtensionProperty.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 94c422e8628..66294d455e6 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -665,11 +665,6 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolveWithStdlib/problems/cloneArray.kt"); } - @TestMetadata("complexSmartCasts.kt") - public void testComplexSmartCasts() throws Exception { - runTest("compiler/fir/resolve/testData/resolveWithStdlib/problems/complexSmartCasts.kt"); - } - @TestMetadata("delegateTypeMismatch.kt") public void testDelegateTypeMismatch() throws Exception { runTest("compiler/fir/resolve/testData/resolveWithStdlib/problems/delegateTypeMismatch.kt");