diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index ed8d5714d13..050415d6ab2 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -3844,6 +3844,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInIfElse.kt"); } + @TestMetadata("assignedInTryWithCatch.kt") + public void testAssignedInTryWithCatch() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.kt"); + } + + @TestMetadata("assignedInTryWithoutCatch.kt") + public void testAssignedInTryWithoutCatch() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.kt"); + } + @TestMetadata("assignmentInLocalsInConstructor.kt") public void testAssignmentInLocalsInConstructor() throws Exception { runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.kt"); diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.fir.kt new file mode 100644 index 00000000000..09c54d7085a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.fir.kt @@ -0,0 +1,70 @@ +fun assignedInTry() { + val a: Int + try { + a = 42 + } catch (e: Exception) { + } finally { + } + a.hashCode() +} + +fun sideEffectBeforeAssignmentInTry(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } catch (e: Exception) { + } finally { + } + a.hashCode() +} + +fun assignedInTryAndCatch() { + val a: Int + try { + a = 42 + } catch (e: Exception) { + a = 41 + } finally { + } + a.hashCode() +} + +fun sideEffectBeforeAssignedInTryAndCatch(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } catch (e: Exception) { + s as String // Potential cast exception + a = 41 + } finally { + } + a.hashCode() +} + +fun assignedAtAll() { + val a: Int + try { + a = 42 + } catch (e: Exception) { + a = 41 + } finally { + a = 40 + } + a.hashCode() +} + +fun sideEffectBeforeAssignedInTryCatchButNotFinally(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } catch (e: Exception) { + s as String // Potential cast exception + a = 41 + } finally { + a = 40 + } + a.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.kt new file mode 100644 index 00000000000..94007a45493 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.kt @@ -0,0 +1,70 @@ +fun assignedInTry() { + val a: Int + try { + a = 42 + } catch (e: Exception) { + } finally { + } + a.hashCode() +} + +fun sideEffectBeforeAssignmentInTry(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } catch (e: Exception) { + } finally { + } + a.hashCode() +} + +fun assignedInTryAndCatch() { + val a: Int + try { + a = 42 + } catch (e: Exception) { + a = 41 + } finally { + } + a.hashCode() +} + +fun sideEffectBeforeAssignedInTryAndCatch(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } catch (e: Exception) { + s as String // Potential cast exception + a = 41 + } finally { + } + a.hashCode() +} + +fun assignedAtAll() { + val a: Int + try { + a = 42 + } catch (e: Exception) { + a = 41 + } finally { + a = 40 + } + a.hashCode() +} + +fun sideEffectBeforeAssignedInTryCatchButNotFinally(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } catch (e: Exception) { + s as String // Potential cast exception + a = 41 + } finally { + a = 40 + } + a.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.txt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.txt new file mode 100644 index 00000000000..3746387c84b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.txt @@ -0,0 +1,8 @@ +package + +public fun assignedAtAll(): kotlin.Unit +public fun assignedInTry(): kotlin.Unit +public fun assignedInTryAndCatch(): kotlin.Unit +public fun sideEffectBeforeAssignedInTryAndCatch(/*0*/ s: kotlin.Any): kotlin.Unit +public fun sideEffectBeforeAssignedInTryCatchButNotFinally(/*0*/ s: kotlin.Any): kotlin.Unit +public fun sideEffectBeforeAssignmentInTry(/*0*/ s: kotlin.Any): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.fir.kt new file mode 100644 index 00000000000..f4e05210985 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.fir.kt @@ -0,0 +1,39 @@ +fun assignedInTry() { + val a: Int + try { + a = 42 + } finally { + } + a.hashCode() +} + +fun sideEffectBeforeAssignmentInTry(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } finally { + } + a.hashCode() +} + +fun assignedInTryAndFinally() { + val a: Int + try { + a = 42 + } finally { + a = 41 + } + a.hashCode() +} + +fun sideEffectBeforeAssignmentInTryButNotFinally(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } finally { + a = 41 + } + a.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.kt new file mode 100644 index 00000000000..4b4ad99461a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.kt @@ -0,0 +1,39 @@ +fun assignedInTry() { + val a: Int + try { + a = 42 + } finally { + } + a.hashCode() +} + +fun sideEffectBeforeAssignmentInTry(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } finally { + } + a.hashCode() +} + +fun assignedInTryAndFinally() { + val a: Int + try { + a = 42 + } finally { + a = 41 + } + a.hashCode() +} + +fun sideEffectBeforeAssignmentInTryButNotFinally(s: Any) { + val a: Int + try { + s as String // Potential cast exception + a = 42 + } finally { + a = 41 + } + a.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.txt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.txt new file mode 100644 index 00000000000..b318855e731 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.txt @@ -0,0 +1,6 @@ +package + +public fun assignedInTry(): kotlin.Unit +public fun assignedInTryAndFinally(): kotlin.Unit +public fun sideEffectBeforeAssignmentInTry(/*0*/ s: kotlin.Any): kotlin.Unit +public fun sideEffectBeforeAssignmentInTryButNotFinally(/*0*/ s: kotlin.Any): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 83bf7f40210..e23d26b24d5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -3851,6 +3851,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInIfElse.kt"); } + @TestMetadata("assignedInTryWithCatch.kt") + public void testAssignedInTryWithCatch() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.kt"); + } + + @TestMetadata("assignedInTryWithoutCatch.kt") + public void testAssignedInTryWithoutCatch() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.kt"); + } + @TestMetadata("assignmentInLocalsInConstructor.kt") public void testAssignmentInLocalsInConstructor() throws Exception { runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index fbf37f80c75..9f99f77e625 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -3846,6 +3846,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInIfElse.kt"); } + @TestMetadata("assignedInTryWithCatch.kt") + public void testAssignedInTryWithCatch() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithCatch.kt"); + } + + @TestMetadata("assignedInTryWithoutCatch.kt") + public void testAssignedInTryWithoutCatch() throws Exception { + runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInTryWithoutCatch.kt"); + } + @TestMetadata("assignmentInLocalsInConstructor.kt") public void testAssignmentInLocalsInConstructor() throws Exception { runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.kt");