From 77c260138279feb970bdbe768c89ab58c9272f02 Mon Sep 17 00:00:00 2001 From: pyos Date: Wed, 28 Sep 2022 14:33:12 +0200 Subject: [PATCH] Add a test where a local variable has the same name as a property --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../smartCasts/implicitThisOrLocalVar.fir.kt | 26 +++++++++++++++++++ .../smartCasts/implicitThisOrLocalVar.kt | 26 +++++++++++++++++++ .../smartCasts/implicitThisOrLocalVar.txt | 13 ++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 7 files changed, 89 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 1f4daa75eff..003fe2fa62e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -28850,6 +28850,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); } + @Test + @TestMetadata("implicitThisOrLocalVar.kt") + public void testImplicitThisOrLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 5602dc93fa3..886d79070af 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -28850,6 +28850,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); } + @Test + @TestMetadata("implicitThisOrLocalVar.kt") + public void testImplicitThisOrLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index ceae35a2422..14fd0b0d85e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -28850,6 +28850,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); } + @Test + @TestMetadata("implicitThisOrLocalVar.kt") + public void testImplicitThisOrLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception { diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.fir.kt new file mode 100644 index 00000000000..6bbb354caf5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.fir.kt @@ -0,0 +1,26 @@ +class Box(var item: String?) + +fun take(it: T) {} + +fun Box.test() { + val other = Box("") + myRun { + if (item != null) { + take(item) + other.item = null + take(item) + this.item = null + take(item) + } + } + + var item: String? = "OK" + myRun { + if (item != null) { + this.item = null + take(item) + } + } +} + +fun myRun(block: () -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt new file mode 100644 index 00000000000..ea224ac5e12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt @@ -0,0 +1,26 @@ +class Box(var item: String?) + +fun take(it: T) {} + +fun Box.test() { + val other = Box("") + myRun { + if (item != null) { + take(item) + other.item = null + take(item) + this.item = null + take(item) + } + } + + var item: String? = "OK" + myRun { + if (item != null) { + this.item = null + take(item) + } + } +} + +fun myRun(block: () -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.txt b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.txt new file mode 100644 index 00000000000..34d8e8a89f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.txt @@ -0,0 +1,13 @@ +package + +public fun myRun(/*0*/ block: () -> kotlin.Unit): kotlin.Unit +public fun take(/*0*/ it: T): kotlin.Unit +public fun Box.test(): kotlin.Unit + +public final class Box { + public constructor Box(/*0*/ item: kotlin.String?) + public final var item: kotlin.String? + 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/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 50c1cdae962..5abc3aa6392 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -28940,6 +28940,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); } + @Test + @TestMetadata("implicitThisOrLocalVar.kt") + public void testImplicitThisOrLocalVar() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOrLocalVar.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception {