From c6b32200df4afe1230664f6314a0cebd03a3027c Mon Sep 17 00:00:00 2001 From: "Aleksandra.Arsenteva" Date: Tue, 28 Nov 2023 16:50:14 +0300 Subject: [PATCH] [Test] Add diagnostic tests for smartcast in K2 List of issues: KT-28806, KT-7186, KT-22997, KT-1982, KT-22996, KT-54443, KT-37308, KT-37115, KT-4113, KT-25747, KT-24779 --- ...CompilerTestFE10TestdataTestGenerated.java | 82 +++ ...sticCompilerFE10TestDataTestGenerated.java | 82 +++ ...eeOldFrontendDiagnosticsTestGenerated.java | 82 +++ ...siOldFrontendDiagnosticsTestGenerated.java | 82 +++ .../binaryOperatorsWithJumps.fir.kt | 130 ++++ .../smartCasts/binaryOperatorsWithJumps.kt | 130 ++++ .../comparisonOfBuiltInTypesUnderOr.fir.kt | 121 ++++ .../comparisonOfBuiltInTypesUnderOr.kt | 121 ++++ .../comparisonOfClassTypesUnderOr.fir.kt | 153 +++++ .../comparisonOfClassTypesUnderOr.kt | 153 +++++ .../lambdaWithCallInPlace.fir.kt | 622 ++++++++++++++++++ .../lambdaWithCallInPlace.kt | 622 ++++++++++++++++++ .../lambdaWithCallInPlaceAndBounds.fir.kt | 378 +++++++++++ .../lambdaWithCallInPlaceAndBounds.kt | 378 +++++++++++ .../lambdaWithCallInPlaceAndDelegate.kt | 82 +++ .../lambdaWithCallInPlaceAndOperators.kt | 58 ++ .../lambdaWithImpliesContract.fir.kt | 55 ++ .../lambdaWithImpliesContract.kt | 55 ++ .../tests/smartCasts/nullableLambda.fir.kt | 56 ++ .../tests/smartCasts/nullableLambda.kt | 56 ++ .../smartCasts/safecalls/childProperty.fir.kt | 29 + .../smartCasts/safecalls/childProperty.kt | 29 + .../smartCasts/savedSmartcastResult.fir.kt | 35 + .../tests/smartCasts/savedSmartcastResult.kt | 35 + .../smartCasts/typeParameterWithBounds.fir.kt | 47 ++ .../smartCasts/typeParameterWithBounds.kt | 47 ++ .../test/runners/DiagnosticTestGenerated.java | 82 +++ 27 files changed, 3802 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/nullableLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index a4fa866aa30..b21b4c6f75d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -34156,6 +34156,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt"); } + @Test + @TestMetadata("binaryOperatorsWithJumps.kt") + public void testBinaryOperatorsWithJumps() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt"); + } + @Test @TestMetadata("classObjectMember.kt") public void testClassObjectMember() throws Exception { @@ -34168,6 +34174,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt"); } + @Test + @TestMetadata("comparisonOfBuiltInTypesUnderOr.kt") + public void testComparisonOfBuiltInTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt"); + } + + @Test + @TestMetadata("comparisonOfClassTypesUnderOr.kt") + public void testComparisonOfClassTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt"); + } + @Test @TestMetadata("comparisonUnderAnd.kt") public void testComparisonUnderAnd() throws Exception { @@ -34720,6 +34738,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt"); } + @Test + @TestMetadata("nullableLambda.kt") + public void testNullableLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt"); + } + @Test @TestMetadata("openInSealed.kt") public void testOpenInSealed() throws Exception { @@ -34750,6 +34774,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/safeAs.kt"); } + @Test + @TestMetadata("savedSmartcastResult.kt") + public void testSavedSmartcastResult() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt"); + } + @Test @TestMetadata("severalSmartCastsOnReified.kt") public void testSeveralSmartCastsOnReified() throws Exception { @@ -34888,6 +34918,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/typeInComparison.kt"); } + @Test + @TestMetadata("typeParameterWithBounds.kt") + public void testTypeParameterWithBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt"); + } + @Test @TestMetadata("unstableToStable.kt") public void testUnstableToStable() throws Exception { @@ -35276,6 +35312,46 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts") + @TestDataPath("$PROJECT_ROOT") + public class LambdasWithContracts { + @Test + public void testAllFilesPresentInLambdasWithContracts() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("lambdaWithCallInPlace.kt") + public void testLambdaWithCallInPlace() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndBounds.kt") + public void testLambdaWithCallInPlaceAndBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndDelegate.kt") + public void testLambdaWithCallInPlaceAndDelegate() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndOperators.kt") + public void testLambdaWithCallInPlaceAndOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt"); + } + + @Test + @TestMetadata("lambdaWithImpliesContract.kt") + public void testLambdaWithImpliesContract() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/loops") @TestDataPath("$PROJECT_ROOT") @@ -35795,6 +35871,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.kt"); } + @Test + @TestMetadata("childProperty.kt") + public void testChildProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt"); + } + @Test @TestMetadata("doubleCall.kt") public void testDoubleCall() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 628a12596c4..a344310355e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -34156,6 +34156,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt"); } + @Test + @TestMetadata("binaryOperatorsWithJumps.kt") + public void testBinaryOperatorsWithJumps() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt"); + } + @Test @TestMetadata("classObjectMember.kt") public void testClassObjectMember() throws Exception { @@ -34168,6 +34174,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt"); } + @Test + @TestMetadata("comparisonOfBuiltInTypesUnderOr.kt") + public void testComparisonOfBuiltInTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt"); + } + + @Test + @TestMetadata("comparisonOfClassTypesUnderOr.kt") + public void testComparisonOfClassTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt"); + } + @Test @TestMetadata("comparisonUnderAnd.kt") public void testComparisonUnderAnd() throws Exception { @@ -34720,6 +34738,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt"); } + @Test + @TestMetadata("nullableLambda.kt") + public void testNullableLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt"); + } + @Test @TestMetadata("openInSealed.kt") public void testOpenInSealed() throws Exception { @@ -34750,6 +34774,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/safeAs.kt"); } + @Test + @TestMetadata("savedSmartcastResult.kt") + public void testSavedSmartcastResult() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt"); + } + @Test @TestMetadata("severalSmartCastsOnReified.kt") public void testSeveralSmartCastsOnReified() throws Exception { @@ -34888,6 +34918,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/typeInComparison.kt"); } + @Test + @TestMetadata("typeParameterWithBounds.kt") + public void testTypeParameterWithBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt"); + } + @Test @TestMetadata("unstableToStable.kt") public void testUnstableToStable() throws Exception { @@ -35276,6 +35312,46 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts") + @TestDataPath("$PROJECT_ROOT") + public class LambdasWithContracts { + @Test + public void testAllFilesPresentInLambdasWithContracts() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("lambdaWithCallInPlace.kt") + public void testLambdaWithCallInPlace() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndBounds.kt") + public void testLambdaWithCallInPlaceAndBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndDelegate.kt") + public void testLambdaWithCallInPlaceAndDelegate() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndOperators.kt") + public void testLambdaWithCallInPlaceAndOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt"); + } + + @Test + @TestMetadata("lambdaWithImpliesContract.kt") + public void testLambdaWithImpliesContract() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/loops") @TestDataPath("$PROJECT_ROOT") @@ -35795,6 +35871,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.kt"); } + @Test + @TestMetadata("childProperty.kt") + public void testChildProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt"); + } + @Test @TestMetadata("doubleCall.kt") public void testDoubleCall() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 7413d97aa5d..6cb4f38ba42 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -31924,6 +31924,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt"); } + @Test + @TestMetadata("binaryOperatorsWithJumps.kt") + public void testBinaryOperatorsWithJumps() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt"); + } + @Test @TestMetadata("classObjectMember.kt") public void testClassObjectMember() throws Exception { @@ -31936,6 +31942,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt"); } + @Test + @TestMetadata("comparisonOfBuiltInTypesUnderOr.kt") + public void testComparisonOfBuiltInTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt"); + } + + @Test + @TestMetadata("comparisonOfClassTypesUnderOr.kt") + public void testComparisonOfClassTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt"); + } + @Test @TestMetadata("comparisonUnderAnd.kt") public void testComparisonUnderAnd() throws Exception { @@ -32488,6 +32506,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt"); } + @Test + @TestMetadata("nullableLambda.kt") + public void testNullableLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt"); + } + @Test @TestMetadata("openInSealed.kt") public void testOpenInSealed() throws Exception { @@ -32518,6 +32542,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/safeAs.kt"); } + @Test + @TestMetadata("savedSmartcastResult.kt") + public void testSavedSmartcastResult() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt"); + } + @Test @TestMetadata("severalSmartCastsOnReified.kt") public void testSeveralSmartCastsOnReified() throws Exception { @@ -32656,6 +32686,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/typeInComparison.kt"); } + @Test + @TestMetadata("typeParameterWithBounds.kt") + public void testTypeParameterWithBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt"); + } + @Test @TestMetadata("unstableToStable.kt") public void testUnstableToStable() throws Exception { @@ -33044,6 +33080,46 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts") + @TestDataPath("$PROJECT_ROOT") + public class LambdasWithContracts { + @Test + public void testAllFilesPresentInLambdasWithContracts() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform"); + } + + @Test + @TestMetadata("lambdaWithCallInPlace.kt") + public void testLambdaWithCallInPlace() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndBounds.kt") + public void testLambdaWithCallInPlaceAndBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndDelegate.kt") + public void testLambdaWithCallInPlaceAndDelegate() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndOperators.kt") + public void testLambdaWithCallInPlaceAndOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt"); + } + + @Test + @TestMetadata("lambdaWithImpliesContract.kt") + public void testLambdaWithImpliesContract() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/loops") @TestDataPath("$PROJECT_ROOT") @@ -33563,6 +33639,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.kt"); } + @Test + @TestMetadata("childProperty.kt") + public void testChildProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt"); + } + @Test @TestMetadata("doubleCall.kt") public void testDoubleCall() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index aef316a80be..44365d6e39b 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -32044,6 +32044,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt"); } + @Test + @TestMetadata("binaryOperatorsWithJumps.kt") + public void testBinaryOperatorsWithJumps() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt"); + } + @Test @TestMetadata("classObjectMember.kt") public void testClassObjectMember() throws Exception { @@ -32056,6 +32062,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt"); } + @Test + @TestMetadata("comparisonOfBuiltInTypesUnderOr.kt") + public void testComparisonOfBuiltInTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt"); + } + + @Test + @TestMetadata("comparisonOfClassTypesUnderOr.kt") + public void testComparisonOfClassTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt"); + } + @Test @TestMetadata("comparisonUnderAnd.kt") public void testComparisonUnderAnd() throws Exception { @@ -32608,6 +32626,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt"); } + @Test + @TestMetadata("nullableLambda.kt") + public void testNullableLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt"); + } + @Test @TestMetadata("openInSealed.kt") public void testOpenInSealed() throws Exception { @@ -32638,6 +32662,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/safeAs.kt"); } + @Test + @TestMetadata("savedSmartcastResult.kt") + public void testSavedSmartcastResult() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt"); + } + @Test @TestMetadata("severalSmartCastsOnReified.kt") public void testSeveralSmartCastsOnReified() throws Exception { @@ -32776,6 +32806,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/typeInComparison.kt"); } + @Test + @TestMetadata("typeParameterWithBounds.kt") + public void testTypeParameterWithBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt"); + } + @Test @TestMetadata("unstableToStable.kt") public void testUnstableToStable() throws Exception { @@ -33164,6 +33200,46 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts") + @TestDataPath("$PROJECT_ROOT") + public class LambdasWithContracts { + @Test + public void testAllFilesPresentInLambdasWithContracts() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform"); + } + + @Test + @TestMetadata("lambdaWithCallInPlace.kt") + public void testLambdaWithCallInPlace() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndBounds.kt") + public void testLambdaWithCallInPlaceAndBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndDelegate.kt") + public void testLambdaWithCallInPlaceAndDelegate() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndOperators.kt") + public void testLambdaWithCallInPlaceAndOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt"); + } + + @Test + @TestMetadata("lambdaWithImpliesContract.kt") + public void testLambdaWithImpliesContract() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/loops") @TestDataPath("$PROJECT_ROOT") @@ -33683,6 +33759,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.kt"); } + @Test + @TestMetadata("childProperty.kt") + public void testChildProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt"); + } + @Test @TestMetadata("doubleCall.kt") public void testDoubleCall() throws Exception { diff --git a/compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.fir.kt new file mode 100644 index 00000000000..4f034953118 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.fir.kt @@ -0,0 +1,130 @@ +// ISSUE: KT-37115 + +fun test1(foo: String?) { + foo != null || throw IllegalArgumentException() + foo.length +} + +fun test2(foo: String?) { + foo != null || return + foo.length +} + +fun test3(foo: String?) { + while (true) { + foo != null || continue + foo.length + } +} + +fun test4(foo: String?) { + while (true) { + foo == null || break + foo.length + } + foo.length +} + +fun test5(foo: String?) { + while (true) { + foo != null || break + foo.length + } + foo.length +} + +fun test6(foo: String?) { + var i = 0 + while (i == 0) { + foo == null || break + foo.length + } + foo.length +} + +fun test7(foo: String?) { + for (i in 1..3) { + foo != null || break + foo.length + } +} + +fun test8(foo: String?) { + foo == null && throw IllegalArgumentException() + foo.length +} + +fun test9(foo: String?) { + foo == null && return + foo.length +} + +fun test10(foo: String?) { + while (true) { + foo == null && continue + foo.length + } + foo.length +} + +fun test11(foo: String?) { + for (i in 1..3) { + foo == null && continue + foo.length + } +} + +fun test12(foo: String?) { + while (true) { + foo != null && break + foo.length + } + foo.length +} + +fun test13(foo: String?) { + var i = 0 + while (i == 0) { + foo != null && break + foo.length + } + foo.length +} + +fun test14(foo: String?) { + while (true) { + foo == null && break + foo.length + } + foo.length +} + +fun test15(foo: String?) { + for (i in 1..3) { + foo != null && break + } + foo.length +} + +fun test16(foo: String?) { + for (i in 1..3) { + foo == null && break + foo.length + } + foo.length +} + +fun test17(foo: Any?) { + foo !=null && foo is String? || throw IllegalArgumentException() + foo.length +} + +fun test18(foo: Any?) { + foo != null && foo !is String && throw IllegalArgumentException() + var k: String? = foo +} + +fun test19(foo: Any?) { + foo is String || foo == null || throw IllegalArgumentException() + var k: String? = foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt b/compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt new file mode 100644 index 00000000000..b32d6285b67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt @@ -0,0 +1,130 @@ +// ISSUE: KT-37115 + +fun test1(foo: String?) { + foo != null || throw IllegalArgumentException() + foo.length +} + +fun test2(foo: String?) { + foo != null || return + foo.length +} + +fun test3(foo: String?) { + while (true) { + foo != null || continue + foo.length + } +} + +fun test4(foo: String?) { + while (true) { + foo == null || break + foo.length + } + foo.length +} + +fun test5(foo: String?) { + while (true) { + foo != null || break + foo.length + } + foo.length +} + +fun test6(foo: String?) { + var i = 0 + while (i == 0) { + foo == null || break + foo.length + } + foo.length +} + +fun test7(foo: String?) { + for (i in 1..3) { + foo != null || break + foo.length + } +} + +fun test8(foo: String?) { + foo == null && throw IllegalArgumentException() + foo.length +} + +fun test9(foo: String?) { + foo == null && return + foo.length +} + +fun test10(foo: String?) { + while (true) { + foo == null && continue + foo.length + } + foo.length +} + +fun test11(foo: String?) { + for (i in 1..3) { + foo == null && continue + foo.length + } +} + +fun test12(foo: String?) { + while (true) { + foo != null && break + foo.length + } + foo.length +} + +fun test13(foo: String?) { + var i = 0 + while (i == 0) { + foo != null && break + foo.length + } + foo.length +} + +fun test14(foo: String?) { + while (true) { + foo == null && break + foo.length + } + foo.length +} + +fun test15(foo: String?) { + for (i in 1..3) { + foo != null && break + } + foo.length +} + +fun test16(foo: String?) { + for (i in 1..3) { + foo == null && break + foo.length + } + foo.length +} + +fun test17(foo: Any?) { + foo !=null && foo is String? || throw IllegalArgumentException() + foo.length +} + +fun test18(foo: Any?) { + foo != null && foo !is String && throw IllegalArgumentException() + var k: String? = foo +} + +fun test19(foo: Any?) { + foo is String || foo == null || throw IllegalArgumentException() + var k: String? = foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.fir.kt new file mode 100644 index 00000000000..a01304d936e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.fir.kt @@ -0,0 +1,121 @@ +// ISSUE: KT-1982 +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + +fun test1(x: Any?) { + if (x is Any || x == null) { + var k: Any? = x + } else { + var k: Any = x + var k2: Nothing = x + } +} + +fun test2(x: Any?) { + if (x is Any || x != null) { + var k: Any = x + } else { + var k: Any? = x + } +} + +fun test3(x: Any?) { + if (x is Any? || x != null) { + var k: Any? = x + } else { + var k: Nothing = x + var k2: Int = x + } +} + +fun test4(x: Any?) { + if (x !is Any || x != null) { + var k: Any? = x + } else { + var k: Nothing = x + var k2: Any? = x + } +} + +fun test5(x: Any?) { + if (x is String || x == null){ + var k: String? = x + } + else { + var k: Any = x + } +} + +fun test6(x: Any?) { + if (x !is String || x == null){ + var k: Any? = x + } + else { + var k: String = x + } +} + +fun test7(x: Any?) { + if (x is String || x != null){ + var k: Any = x + } + else { + var k: Any? = x + } +} + +fun test8(x: Any?) { + if (x !is String || x != null){ + var k: Any? = x + } + else { + var k: String? = x + } +} + +fun test9(x: Any?) { + if (x is String?){ + var k: String? = x + } + else { + var k: Any = x + } +} + +fun test10(x: Any?) { + if (x !is String?){ + var k: Any = x + } + else { + var k: String? = x + } +} + +fun test11(x: Any?) { + if (x is List<*> || x == null){ + var k : List<*>? = x + } + else { + var k: Any = x + } +} + +fun test12(x: Any?) { + if (x is List<*> || x != null){ + var k2: Any = x + } + else { + var k: Any? = x + } +} + +fun test13(list: List?) { + if (list is ArrayList || list == null) { + var k: ArrayList? = list + } +} + +fun test14(list: List?) { + if (list is ArrayList || list != null) { + var k: ArrayList? = list + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt new file mode 100644 index 00000000000..0fe6da70a51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt @@ -0,0 +1,121 @@ +// ISSUE: KT-1982 +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + +fun test1(x: Any?) { + if (x is Any || x == null) { + var k: Any? = x + } else { + var k: Any = x + var k2: Nothing = x + } +} + +fun test2(x: Any?) { + if (x is Any || x != null) { + var k: Any = x + } else { + var k: Any? = x + } +} + +fun test3(x: Any?) { + if (x is Any? || x != null) { + var k: Any? = x + } else { + var k: Nothing = x + var k2: Int = x + } +} + +fun test4(x: Any?) { + if (x !is Any || x != null) { + var k: Any? = x + } else { + var k: Nothing = x + var k2: Any? = x + } +} + +fun test5(x: Any?) { + if (x is String || x == null){ + var k: String? = x + } + else { + var k: Any = x + } +} + +fun test6(x: Any?) { + if (x !is String || x == null){ + var k: Any? = x + } + else { + var k: String = x + } +} + +fun test7(x: Any?) { + if (x is String || x != null){ + var k: Any = x + } + else { + var k: Any? = x + } +} + +fun test8(x: Any?) { + if (x !is String || x != null){ + var k: Any? = x + } + else { + var k: String? = x + } +} + +fun test9(x: Any?) { + if (x is String?){ + var k: String? = x + } + else { + var k: Any = x + } +} + +fun test10(x: Any?) { + if (x !is String?){ + var k: Any = x + } + else { + var k: String? = x + } +} + +fun test11(x: Any?) { + if (x is List<*> || x == null){ + var k : List<*>? = x + } + else { + var k: Any = x + } +} + +fun test12(x: Any?) { + if (x is List<*> || x != null){ + var k2: Any = x + } + else { + var k: Any? = x + } +} + +fun test13(list: List?) { + if (list is ArrayList || list == null) { + var k: ArrayList? = list + } +} + +fun test14(list: List?) { + if (list is ArrayList || list != null) { + var k: ArrayList? = list + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.fir.kt new file mode 100644 index 00000000000..6fbee76e419 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.fir.kt @@ -0,0 +1,153 @@ +// ISSUE: KT-1982 +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + +interface A +class B : A + +fun test1(x:Any?) { + if (x is A || x !is B) { + var k: B? = x + var k2: A? = x + var k3: Any? = x + } + else { + var k: Any = x + var k2: A = x + var k3: B = x + } +} + +fun test2(x:Any?) { + if (x is A || x is B) { + var k: B = x + var k2: A = x + var k3: Any = x + } + else { + var k: Any? = x + var k2: A = x + var k3: B = x + } +} + +fun test3(x:Any?) { + if (x !is A || x is B) { + var k: B = x + var k2: A = x + var k3: Any? = x + } + else { + var k: Any = x + var k2: A = x + var k3: B = x + } +} + +fun test4(x:Any?) { + if (x is A || x is B || x == null) { + var k: B? = x + var k2: A? = x + var k3: Any? = x + } + else { + var k: Any = x + var k2: A = x + var k3: B = x + } +} + +sealed interface A2 +class B2 : A2 +class C2 : A2 + +fun test5(x:Any?) { + if (x is C2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any = x + } +} + +fun test6(x:Any?) { + if (x is C2 || x !is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + } +} + +fun test7(x:Any?) { + if (x is A2 || x !is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test8(x:Any?) { + if (x is A2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any? = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test9(x:Any?) { + if (x !is A2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test10(x:Any?) { + if (x !is A2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test11(x:A2?) { + if (x !is B2 || x is B2) { + var k: A2? = x + } + else { + var k : B2 = x + var k2 : A2? = x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt new file mode 100644 index 00000000000..4b44085990d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt @@ -0,0 +1,153 @@ +// ISSUE: KT-1982 +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + +interface A +class B : A + +fun test1(x:Any?) { + if (x is A || x !is B) { + var k: B? = x + var k2: A? = x + var k3: Any? = x + } + else { + var k: Any = x + var k2: A = x + var k3: B = x + } +} + +fun test2(x:Any?) { + if (x is A || x is B) { + var k: B = x + var k2: A = x + var k3: Any = x + } + else { + var k: Any? = x + var k2: A = x + var k3: B = x + } +} + +fun test3(x:Any?) { + if (x !is A || x is B) { + var k: B = x + var k2: A = x + var k3: Any? = x + } + else { + var k: Any = x + var k2: A = x + var k3: B = x + } +} + +fun test4(x:Any?) { + if (x is A || x is B || x == null) { + var k: B? = x + var k2: A? = x + var k3: Any? = x + } + else { + var k: Any = x + var k2: A = x + var k3: B = x + } +} + +sealed interface A2 +class B2 : A2 +class C2 : A2 + +fun test5(x:Any?) { + if (x is C2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any = x + } +} + +fun test6(x:Any?) { + if (x is C2 || x !is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + } +} + +fun test7(x:Any?) { + if (x is A2 || x !is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test8(x:Any?) { + if (x is A2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any? = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test9(x:Any?) { + if (x !is A2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test10(x:Any?) { + if (x !is A2 || x is B2) { + var k: B2 = x + var k2: A2 = x + var k3: C2 = x + var k4: Any? = x + } + else { + var k: Any = x + var k2: A2 = x + var k3: B2 = x + var k4 : C2 = x + } +} + +fun test11(x:A2?) { + if (x !is B2 || x is B2) { + var k: A2? = x + } + else { + var k : B2 = x + var k2 : A2? = x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.fir.kt new file mode 100644 index 00000000000..019fc73d12b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.fir.kt @@ -0,0 +1,622 @@ +// ISSUE: KT-28806 +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION, -DEBUG_INFO_SMARTCAST +import kotlin.contracts.* + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun atLeastOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() +} + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun exactlyOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun runWithoutContract(block: () -> Unit): Unit = block() + +fun materialize(): R = null!! + +fun test1() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x.length + x = 10 + } +} + +fun test2() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x.length + x = 10 + } +} + +fun test3() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x.length + x = 10 + } +} + +fun test4() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x = "" + x.length + } +} + +fun test5() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x = "" + x.length + } +} + +fun test6() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x = "" + x.length + } +} + +fun test7() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x.length + runWithoutContract { + x.length + } + x = 10 + } +} + +fun test8() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x.length + exactlyOnce { + x.length + } + x = 10 + } +} + +fun test9() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x.length + atLeastOnce { + x.length + } + x = 10 + } +} + +fun test10() { + var x: Any? = materialize() + runWithoutContract { + val b = x is String + if (b) { + x.length + } + } +} + +fun test11(x: Any) { + exactlyOnce { + val b = x is String + if (b) { + x.length + } + } +} + +fun test12(x: Any) { + atLeastOnce { + val b = x is String + if (b) { + x.length + } + } +} + +fun test13(x: Any) { + if (x is String) { + runWithoutContract { + x.length + } + } +} + +fun test14(x: Any) { + if (x is String) { + exactlyOnce { + x.length + } + } +} + +fun test15(x: Any) { + if (x is String) { + atLeastOnce { + x.length + } + } +} + +fun test16(x: Any) { + atLeastOnce { + when (x) { + is String -> x.length + } + x.length + } +} + +fun test17(x: Any) { + runWithoutContract { + when (x) { + is String -> x.length + } + x.length + } +} + +fun test18(x: Any) { + exactlyOnce { + when (x) { + is String -> x.length + } + x.length + } +} + +fun test19(x: Any) { + when (x) { + is String -> atLeastOnce { + x.length + } + } +} + +fun test20(x: Any) { + when (x) { + is String -> runWithoutContract { + x.length + } + } +} + +fun test21(x: Any) { + when (x) { + is String -> exactlyOnce { + x.length + } + } +} + +fun test22(x: Any) { + val state: Boolean = x is String + runWithoutContract { + if (state) { + x.length + } + } +} + +fun test23(x: Any) { + val state: Boolean = x is String + exactlyOnce { + if (state) { + x.length + } + } +} + +fun test24(x: Any) { + val state: Boolean = x is String + atLeastOnce { + if (state) { + x.length + } + } +} + +fun test25() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x.length + } + x = "" +} + +fun test26() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x.length + } + x = "" +} + +fun test27() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x.length + } + x = "" +} + +fun test28(x: Any) { + runWithoutContract { + require(x is String) + x.length + } + runWithoutContract { + x.length + } +} + +fun test29(x: Any) { + exactlyOnce { + require(x is String) + x.length + } + exactlyOnce { + x.length + } +} + +fun test30(x: Any) { + atLeastOnce { + require(x is String) + x.length + } + atLeastOnce { + x.length + } +} + +fun test31(x: Any) { + runWithoutContract { + require(x is String) + } + x.length +} + +fun test32(x: Any) { + exactlyOnce { + require(x is String) + } + x.length +} + +fun test33(x: Any) { + atLeastOnce { + require(x is String) + } + x.length +} + +fun test34() { + var x: Any? = materialize() + runWithoutContract { + require(x is String) + x = 10 + } + runWithoutContract { + x.length + } +} + +fun test35() { + var x: Any? = materialize() + exactlyOnce { + require(x is String) + x = 10 + } + exactlyOnce { + x.length + } +} + +fun test36() { + var x: Any? = materialize() + atLeastOnce { + require(x is String) + x = 10 + } + atLeastOnce { + x.length + } +} + +fun test37() { + var x: Any? = materialize() + require(x is String) + fun local() { + atLeastOnce { + x.length + } + x = "" + } +} + +fun test38() { + var x: Any? = materialize() + require(x is String) + fun local() { + exactlyOnce { + x.length + } + x = "" + } +} + +fun test39() { + var x: Any? = materialize() + require(x is String) + fun local() { + runWithoutContract { + x.length + } + x = "" + } +} + +fun test40() { + var x: Any? = materialize() + require(x is String) + fun local() { + atLeastOnce { + x.length + } + } +} + +fun test41() { + var x: Any? = materialize() + require(x is String) + fun local() { + exactlyOnce { + x.length + } + } +} + +fun test42() { + var x: Any? = materialize() + require(x is String) + fun local() { + runWithoutContract { + x.length + } + } +} + +fun test43() { + runWithoutContract { + var x: Any? = materialize() + require(x is String) + x.length + x = 10 + } +} + +fun test44() { + atLeastOnce { + var x: Any? = materialize() + require(x is String) + x.length + x = 10 + } +} + +fun test45() { + exactlyOnce { + var x: Any? = materialize() + require(x is String) + x.length + x = 10 + } +} + +fun test46() { + var x: Any = materialize() + exactlyOnce { + while (x is String) { + x.length + x = 10 + } + } +} + +fun test47() { + var x: Any = materialize() + atLeastOnce { + while (x is String) { + x.length + x = 10 + } + } +} + +fun test48() { + var x: Any = materialize() + runWithoutContract { + while (x is String) { + x.length + x = 10 + } + } +} + +fun test49() { + var x: Any = materialize() + while (x is String) { + exactlyOnce { + x.length + x = 10 + } + } +} + +fun test50() { + var x: Any = materialize() + while (x is String) { + atLeastOnce { + x.length + x = 10 + } + } +} + +fun test51() { + var x: Any = materialize() + while (x is String) { + runWithoutContract { + x.length + x = 10 + } + } +} + +fun test52() { + var x: Any = materialize() + exactlyOnce { + do { + x.length + } while (x is String) + } +} + +fun test53() { + var x: Any = materialize() + atLeastOnce { + do { + x.length + } while (x is String) + } +} + +fun test54() { + var x: Any = materialize() + runWithoutContract { + do { + x.length + } while (x is String) + } +} + +fun test55() { + var x: Any = materialize() + runWithoutContract { + for (i in 1..3) { + require(x is String) + x.length + x = 10 + } + } +} + +fun test56() { + var x: Any = materialize() + atLeastOnce { + for (i in 1..3) { + require(x is String) + x.length + x = 10 + } + } +} + +fun test57() { + var x: Any = materialize() + exactlyOnce { + for (i in 1..3) { + require(x is String) + x.length + x = 10 + } + } +} + +fun test58() { + var x: Any = materialize() + for (i in 1..3) { + require(x is String) + runWithoutContract { + x.length + x = 10 + } + } +} + +fun test59() { + var x: Any = materialize() + for (i in 1..3) { + require(x is String) + atLeastOnce { + x.length + x = 10 + } + } +} + +fun test60() { + var x: Any = materialize() + for (i in 1..3) { + require(x is String) + exactlyOnce { + x.length + x = 10 + } + } +} + +fun test61() { + var x: String? = materialize() + runWithoutContract { + x?.length ?: -1 + x = null + } +} + +fun test62() { + var x: String? = materialize() + atLeastOnce { + x?.length ?: -1 + x = null + } +} + +fun test63() { + var x: String? = materialize() + exactlyOnce { + x?.length ?: -1 + x = null + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt new file mode 100644 index 00000000000..7a0c77f74a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt @@ -0,0 +1,622 @@ +// ISSUE: KT-28806 +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION, -DEBUG_INFO_SMARTCAST +import kotlin.contracts.* + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun atLeastOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() +} + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun exactlyOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun runWithoutContract(block: () -> Unit): Unit = block() + +fun materialize(): R = null!! + +fun test1() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x.length + x = 10 + } +} + +fun test2() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x.length + x = 10 + } +} + +fun test3() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x.length + x = 10 + } +} + +fun test4() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x = "" + x.length + } +} + +fun test5() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x = "" + x.length + } +} + +fun test6() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x = "" + x.length + } +} + +fun test7() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x.length + runWithoutContract { + x.length + } + x = 10 + } +} + +fun test8() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x.length + exactlyOnce { + x.length + } + x = 10 + } +} + +fun test9() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x.length + atLeastOnce { + x.length + } + x = 10 + } +} + +fun test10() { + var x: Any? = materialize() + runWithoutContract { + val b = x is String + if (b) { + x.length + } + } +} + +fun test11(x: Any) { + exactlyOnce { + val b = x is String + if (b) { + x.length + } + } +} + +fun test12(x: Any) { + atLeastOnce { + val b = x is String + if (b) { + x.length + } + } +} + +fun test13(x: Any) { + if (x is String) { + runWithoutContract { + x.length + } + } +} + +fun test14(x: Any) { + if (x is String) { + exactlyOnce { + x.length + } + } +} + +fun test15(x: Any) { + if (x is String) { + atLeastOnce { + x.length + } + } +} + +fun test16(x: Any) { + atLeastOnce { + when (x) { + is String -> x.length + } + x.length + } +} + +fun test17(x: Any) { + runWithoutContract { + when (x) { + is String -> x.length + } + x.length + } +} + +fun test18(x: Any) { + exactlyOnce { + when (x) { + is String -> x.length + } + x.length + } +} + +fun test19(x: Any) { + when (x) { + is String -> atLeastOnce { + x.length + } + } +} + +fun test20(x: Any) { + when (x) { + is String -> runWithoutContract { + x.length + } + } +} + +fun test21(x: Any) { + when (x) { + is String -> exactlyOnce { + x.length + } + } +} + +fun test22(x: Any) { + val state: Boolean = x is String + runWithoutContract { + if (state) { + x.length + } + } +} + +fun test23(x: Any) { + val state: Boolean = x is String + exactlyOnce { + if (state) { + x.length + } + } +} + +fun test24(x: Any) { + val state: Boolean = x is String + atLeastOnce { + if (state) { + x.length + } + } +} + +fun test25() { + var x: Any? = materialize() + require(x is String) + runWithoutContract { + x.length + } + x = "" +} + +fun test26() { + var x: Any? = materialize() + require(x is String) + exactlyOnce { + x.length + } + x = "" +} + +fun test27() { + var x: Any? = materialize() + require(x is String) + atLeastOnce { + x.length + } + x = "" +} + +fun test28(x: Any) { + runWithoutContract { + require(x is String) + x.length + } + runWithoutContract { + x.length + } +} + +fun test29(x: Any) { + exactlyOnce { + require(x is String) + x.length + } + exactlyOnce { + x.length + } +} + +fun test30(x: Any) { + atLeastOnce { + require(x is String) + x.length + } + atLeastOnce { + x.length + } +} + +fun test31(x: Any) { + runWithoutContract { + require(x is String) + } + x.length +} + +fun test32(x: Any) { + exactlyOnce { + require(x is String) + } + x.length +} + +fun test33(x: Any) { + atLeastOnce { + require(x is String) + } + x.length +} + +fun test34() { + var x: Any? = materialize() + runWithoutContract { + require(x is String) + x = 10 + } + runWithoutContract { + x.length + } +} + +fun test35() { + var x: Any? = materialize() + exactlyOnce { + require(x is String) + x = 10 + } + exactlyOnce { + x.length + } +} + +fun test36() { + var x: Any? = materialize() + atLeastOnce { + require(x is String) + x = 10 + } + atLeastOnce { + x.length + } +} + +fun test37() { + var x: Any? = materialize() + require(x is String) + fun local() { + atLeastOnce { + x.length + } + x = "" + } +} + +fun test38() { + var x: Any? = materialize() + require(x is String) + fun local() { + exactlyOnce { + x.length + } + x = "" + } +} + +fun test39() { + var x: Any? = materialize() + require(x is String) + fun local() { + runWithoutContract { + x.length + } + x = "" + } +} + +fun test40() { + var x: Any? = materialize() + require(x is String) + fun local() { + atLeastOnce { + x.length + } + } +} + +fun test41() { + var x: Any? = materialize() + require(x is String) + fun local() { + exactlyOnce { + x.length + } + } +} + +fun test42() { + var x: Any? = materialize() + require(x is String) + fun local() { + runWithoutContract { + x.length + } + } +} + +fun test43() { + runWithoutContract { + var x: Any? = materialize() + require(x is String) + x.length + x = 10 + } +} + +fun test44() { + atLeastOnce { + var x: Any? = materialize() + require(x is String) + x.length + x = 10 + } +} + +fun test45() { + exactlyOnce { + var x: Any? = materialize() + require(x is String) + x.length + x = 10 + } +} + +fun test46() { + var x: Any = materialize() + exactlyOnce { + while (x is String) { + x.length + x = 10 + } + } +} + +fun test47() { + var x: Any = materialize() + atLeastOnce { + while (x is String) { + x.length + x = 10 + } + } +} + +fun test48() { + var x: Any = materialize() + runWithoutContract { + while (x is String) { + x.length + x = 10 + } + } +} + +fun test49() { + var x: Any = materialize() + while (x is String) { + exactlyOnce { + x.length + x = 10 + } + } +} + +fun test50() { + var x: Any = materialize() + while (x is String) { + atLeastOnce { + x.length + x = 10 + } + } +} + +fun test51() { + var x: Any = materialize() + while (x is String) { + runWithoutContract { + x.length + x = 10 + } + } +} + +fun test52() { + var x: Any = materialize() + exactlyOnce { + do { + x.length + } while (x is String) + } +} + +fun test53() { + var x: Any = materialize() + atLeastOnce { + do { + x.length + } while (x is String) + } +} + +fun test54() { + var x: Any = materialize() + runWithoutContract { + do { + x.length + } while (x is String) + } +} + +fun test55() { + var x: Any = materialize() + runWithoutContract { + for (i in 1..3) { + require(x is String) + x.length + x = 10 + } + } +} + +fun test56() { + var x: Any = materialize() + atLeastOnce { + for (i in 1..3) { + require(x is String) + x.length + x = 10 + } + } +} + +fun test57() { + var x: Any = materialize() + exactlyOnce { + for (i in 1..3) { + require(x is String) + x.length + x = 10 + } + } +} + +fun test58() { + var x: Any = materialize() + for (i in 1..3) { + require(x is String) + runWithoutContract { + x.length + x = 10 + } + } +} + +fun test59() { + var x: Any = materialize() + for (i in 1..3) { + require(x is String) + atLeastOnce { + x.length + x = 10 + } + } +} + +fun test60() { + var x: Any = materialize() + for (i in 1..3) { + require(x is String) + exactlyOnce { + x.length + x = 10 + } + } +} + +fun test61() { + var x: String? = materialize() + runWithoutContract { + x?.length ?: -1 + x = null + } +} + +fun test62() { + var x: String? = materialize() + atLeastOnce { + x?.length ?: -1 + x = null + } +} + +fun test63() { + var x: String? = materialize() + exactlyOnce { + x?.length ?: -1 + x = null + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.fir.kt new file mode 100644 index 00000000000..1e6483652aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.fir.kt @@ -0,0 +1,378 @@ +// ISSUE: KT-28806 +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION, -DEBUG_INFO_SMARTCAST +import kotlin.contracts.* + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun atLeastOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() +} + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun exactlyOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun runWithoutContract(block: () -> Unit): Unit = block() + +fun materialize(): R = null!! + +fun test1(x: Any) { + var y = x + require(y is String) + runWithoutContract { + y = 10 + y = x + x.length + y.length + } +} + +fun test2(x: Any) { + var y = x + require(y is String) + exactlyOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test3(x: Any) { + var y = x + require(y is String) + atLeastOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test4(x: Any) { + var y: Any + require(x is String) + runWithoutContract { + y = 10 + y = x + x.length + y.length + } +} + +fun test5(x: Any) { + var y: Any + require(x is String) + exactlyOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test6(x: Any) { + var y: Any + require(x is String) + atLeastOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test7(x: Any) { + var y: Any? + val b = x is String + if (b) { + y = x + exactlyOnce { + x.length + y.length + } + } +} + +fun test8(x: Any) { + var y: Any? + val b = x is String + if (b) { + y = x + atLeastOnce { + x.length + y.length + } + } +} + +fun test9(x: Any) { + var y: Any? + val b = x is String + if (b) { + y = x + runWithoutContract { + x.length + y.length + } + } +} + +fun test10(x: Any) { + var y = x + runWithoutContract { + require(y is String) + x.length + y.length + } +} + +fun test11(x: Any) { + var y = x + atLeastOnce { + require(y is String) + x.length + y.length + } +} + +fun test12(x: Any) { + var y = x + exactlyOnce { + require(y is String) + x.length + y.length + } +} + +fun test13() { + var x: Any? = materialize() + var y = x + atLeastOnce { + require(y is String) + x = 10 + y = x + y.length + y.inc() + } +} + +fun test14() { + var x: Any? = materialize() + var y = x + exactlyOnce { + require(y is String) + x = 10 + y = x + y.length + y.inc() + } +} + +fun test15() { + var x: Any? = materialize() + var y = x + runWithoutContract { + require(y is String) + x = 10 + y = x + y.length + y.inc() + } +} + +fun test16(x: Any) { + var y: Any + runWithoutContract { + require(x is String) + y = x + y.length + } +} + +fun test17(x: Any) { + var y: Any + exactlyOnce { + require(x is String) + y = x + y.length + } +} + +fun test18(x: Any) { + var y: Any + atLeastOnce { + require(x is String) + y = x + y.length + } +} + +fun test19(x: Any?) { + var y: Any + atLeastOnce { + if (x != null) { + y = x + } else { + y = x + } + require(x is String) + y.length + } +} + +fun test20(x: Any?) { + var y: Any + exactlyOnce { + if (x != null) { + y = x + } else { + y = x + } + require(x is String) + y.length + } +} + +fun test21(x: Any?) { + var y: Any + runWithoutContract { + if (x != null) { + y = x + } else { + y = x + } + require(x is String) + y.length + } +} + +fun test22(x: Any) { + var y: Any = materialize() + runWithoutContract { + require(x is String) + y = x + } + y.length +} + +fun test23(x: Any) { + var y: Any + exactlyOnce { + require(x is String) + y = x + } + y.length +} + +fun test24(x: Any) { + var y: Any + atLeastOnce { + require(x is String) + y = x + } + y.length +} + +fun test25(x: Any) { + var y = x + exactlyOnce { + while (x is String) { + y.length + } + } +} + +fun test26(x: Any) { + var y = x + atLeastOnce { + while (x is String) { + y.length + } + } +} + +fun test27(x: Any) { + var y = x + runWithoutContract { + while (x is String) { + y.length + } + } +} + +fun test28() { + var x: Any? = materialize() + var y = x + exactlyOnce { + while (x is String) { + y.length + x = 10 + } + } +} + +fun test29() { + var x: Any? = materialize() + var y = x + atLeastOnce { + while (x is String) { + y.length + x = 10 + } + } +} + +fun test30() { + var x: Any? = materialize() + var y = x + runWithoutContract { + while (x is String) { + y.length + x = 10 + } + } +} + +fun test31() { + var x: Any? = materialize() + var y = x + exactlyOnce { + while (x is String) { + y.length + x.length + } + x = 10 + } +} + +fun test32() { + var x: Any? = materialize() + var y = x + atLeastOnce { + while (x is String) { + y.length + x.length + } + x = 10 + } +} + +fun test33() { + var x: Any? = materialize() + var y = x + runWithoutContract { + while (x is String) { + y.length + x.length + } + x = 10 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt new file mode 100644 index 00000000000..43c151408e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt @@ -0,0 +1,378 @@ +// ISSUE: KT-28806 +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION, -DEBUG_INFO_SMARTCAST +import kotlin.contracts.* + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun atLeastOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() +} + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun exactlyOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun runWithoutContract(block: () -> Unit): Unit = block() + +fun materialize(): R = null!! + +fun test1(x: Any) { + var y = x + require(y is String) + runWithoutContract { + y = 10 + y = x + x.length + y.length + } +} + +fun test2(x: Any) { + var y = x + require(y is String) + exactlyOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test3(x: Any) { + var y = x + require(y is String) + atLeastOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test4(x: Any) { + var y: Any + require(x is String) + runWithoutContract { + y = 10 + y = x + x.length + y.length + } +} + +fun test5(x: Any) { + var y: Any + require(x is String) + exactlyOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test6(x: Any) { + var y: Any + require(x is String) + atLeastOnce { + y = 10 + y = x + x.length + y.length + } +} + +fun test7(x: Any) { + var y: Any? + val b = x is String + if (b) { + y = x + exactlyOnce { + x.length + y.length + } + } +} + +fun test8(x: Any) { + var y: Any? + val b = x is String + if (b) { + y = x + atLeastOnce { + x.length + y.length + } + } +} + +fun test9(x: Any) { + var y: Any? + val b = x is String + if (b) { + y = x + runWithoutContract { + x.length + y.length + } + } +} + +fun test10(x: Any) { + var y = x + runWithoutContract { + require(y is String) + x.length + y.length + } +} + +fun test11(x: Any) { + var y = x + atLeastOnce { + require(y is String) + x.length + y.length + } +} + +fun test12(x: Any) { + var y = x + exactlyOnce { + require(y is String) + x.length + y.length + } +} + +fun test13() { + var x: Any? = materialize() + var y = x + atLeastOnce { + require(y is String) + x = 10 + y = x + y.length + y.inc() + } +} + +fun test14() { + var x: Any? = materialize() + var y = x + exactlyOnce { + require(y is String) + x = 10 + y = x + y.length + y.inc() + } +} + +fun test15() { + var x: Any? = materialize() + var y = x + runWithoutContract { + require(y is String) + x = 10 + y = x + y.length + y.inc() + } +} + +fun test16(x: Any) { + var y: Any + runWithoutContract { + require(x is String) + y = x + y.length + } +} + +fun test17(x: Any) { + var y: Any + exactlyOnce { + require(x is String) + y = x + y.length + } +} + +fun test18(x: Any) { + var y: Any + atLeastOnce { + require(x is String) + y = x + y.length + } +} + +fun test19(x: Any?) { + var y: Any + atLeastOnce { + if (x != null) { + y = x + } else { + y = x + } + require(x is String) + y.length + } +} + +fun test20(x: Any?) { + var y: Any + exactlyOnce { + if (x != null) { + y = x + } else { + y = x + } + require(x is String) + y.length + } +} + +fun test21(x: Any?) { + var y: Any + runWithoutContract { + if (x != null) { + y = x + } else { + y = x + } + require(x is String) + y.length + } +} + +fun test22(x: Any) { + var y: Any = materialize() + runWithoutContract { + require(x is String) + y = x + } + y.length +} + +fun test23(x: Any) { + var y: Any + exactlyOnce { + require(x is String) + y = x + } + y.length +} + +fun test24(x: Any) { + var y: Any + atLeastOnce { + require(x is String) + y = x + } + y.length +} + +fun test25(x: Any) { + var y = x + exactlyOnce { + while (x is String) { + y.length + } + } +} + +fun test26(x: Any) { + var y = x + atLeastOnce { + while (x is String) { + y.length + } + } +} + +fun test27(x: Any) { + var y = x + runWithoutContract { + while (x is String) { + y.length + } + } +} + +fun test28() { + var x: Any? = materialize() + var y = x + exactlyOnce { + while (x is String) { + y.length + x = 10 + } + } +} + +fun test29() { + var x: Any? = materialize() + var y = x + atLeastOnce { + while (x is String) { + y.length + x = 10 + } + } +} + +fun test30() { + var x: Any? = materialize() + var y = x + runWithoutContract { + while (x is String) { + y.length + x = 10 + } + } +} + +fun test31() { + var x: Any? = materialize() + var y = x + exactlyOnce { + while (x is String) { + y.length + x.length + } + x = 10 + } +} + +fun test32() { + var x: Any? = materialize() + var y = x + atLeastOnce { + while (x is String) { + y.length + x.length + } + x = 10 + } +} + +fun test33() { + var x: Any? = materialize() + var y = x + runWithoutContract { + while (x is String) { + y.length + x.length + } + x = 10 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt new file mode 100644 index 00000000000..9e5891c1879 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt @@ -0,0 +1,82 @@ +// ISSUE: KT-28806 +// FIR_IDENTICAL +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION +import kotlin.contracts.* +import kotlin.reflect.KProperty + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun atLeastOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() +} + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun exactlyOnce(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun runWithoutContract(block: () -> Unit): Unit = block() + +class Delegate { + operator fun getValue(thisRef: Any?, property: KProperty<*>): Any { + TODO() + } + + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Any) { + TODO() + } +} + +fun test1() { + var x: Any by Delegate() + require(x is String) + runWithoutContract { + x.length + } +} + +fun test2() { + var x: Any by Delegate() + require(x is String) + atLeastOnce { + x.length + } +} + +fun test3() { + var x: Any by Delegate() + require(x is String) + exactlyOnce { + x.length + } +} + +fun test4() { + val x: Any by Delegate() + require(x is String) + runWithoutContract { + x.length + } +} + +fun test5() { + val x: Any by Delegate() + require(x is String) + atLeastOnce { + x.length + } +} + +fun test6() { + val x: Any by Delegate() + require(x is String) + exactlyOnce { + x.length + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt new file mode 100644 index 00000000000..f95b139ad73 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt @@ -0,0 +1,58 @@ +// ISSUE: KT-28806 +// FIR_IDENTICAL +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION, -DEBUG_INFO_SMARTCAST +import kotlin.contracts.* + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun atLeastOnce(block: () -> Unit): Boolean { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() + return true +} + +@Suppress("OPT_IN_USAGE_ERROR", "OPT_IN_USAGE_FUTURE_ERROR") +fun exactlyOnce(block: () -> Unit): Boolean { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() + return true +} + +fun runWithoutContract(block: () -> Unit): Boolean { + block() + return true +} + +fun test1(x: Any) { + if (x !is String || atLeastOnce { x.length }) return +} + +fun test2(x: Any) { + if (x !is String || exactlyOnce { x.length }) return +} + +fun test3(x: Any) { + if (x !is String || runWithoutContract { x.length }) return +} + +fun test4(x: Any) { + if (x is String && atLeastOnce { x.length }) { + x.length + } +} + +fun test5(x: Any) { + if (x is String && exactlyOnce { x.length }) { + x.length + } +} + +fun test6(x: Any) { + if (x is String && runWithoutContract { x.length }) { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.fir.kt new file mode 100644 index 00000000000..b5e2aa8a293 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.fir.kt @@ -0,0 +1,55 @@ +// ISSUE: KT-37308 +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION +import kotlin.contracts.* + +@OptIn(ExperimentalContracts::class) +fun CharSequence?.valueIsNotNull(): Boolean { + contract { + returns(true) implies (this@valueIsNotNull != null) + } + return this != null +} +@OptIn(ExperimentalContracts::class) +fun CharSequence?.valueIsNull(): Boolean { + contract { + returns(false) implies (this@valueIsNull != null) + } + return this == null +} + +class A { + val b: String? = "" + val e: C? = C() +} + +class C { + val d: String? = "" +} + +fun test1(a: A?) { + if (!a?.b.valueIsNull()) { + a.b.length + } +} + +fun test2(a: A?) { + require(!a?.b.valueIsNull()) + a.b.length +} + +fun test3(a: A?) { + if(a?.b.valueIsNotNull()){ + a.b.length + } +} + +fun test4(a :A?) { + require(a?.b.valueIsNotNull()) + a.b.length +} + +fun test5(a :A?) { + require(a?.e?.d.valueIsNotNull()) + a.e.d.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt new file mode 100644 index 00000000000..6bb196bf197 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt @@ -0,0 +1,55 @@ +// ISSUE: KT-37308 +// WITH_STDLIB +// DIAGNOSTICS: -ERROR_SUPPRESSION +import kotlin.contracts.* + +@OptIn(ExperimentalContracts::class) +fun CharSequence?.valueIsNotNull(): Boolean { + contract { + returns(true) implies (this@valueIsNotNull != null) + } + return this != null +} +@OptIn(ExperimentalContracts::class) +fun CharSequence?.valueIsNull(): Boolean { + contract { + returns(false) implies (this@valueIsNull != null) + } + return this == null +} + +class A { + val b: String? = "" + val e: C? = C() +} + +class C { + val d: String? = "" +} + +fun test1(a: A?) { + if (!a?.b.valueIsNull()) { + a.b.length + } +} + +fun test2(a: A?) { + require(!a?.b.valueIsNull()) + a.b.length +} + +fun test3(a: A?) { + if(a?.b.valueIsNotNull()){ + a.b.length + } +} + +fun test4(a :A?) { + require(a?.b.valueIsNotNull()) + a.b.length +} + +fun test5(a :A?) { + require(a?.e?.d.valueIsNotNull()) + a.e.d.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/nullableLambda.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/nullableLambda.fir.kt new file mode 100644 index 00000000000..80a7eab2817 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/nullableLambda.fir.kt @@ -0,0 +1,56 @@ +// ISSUE: KT-4113 +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +class Test1(val lambda: (() -> String)?) { + fun foo() { + if (lambda != null) { + lambda.invoke() + lambda() + } + } +} + +fun test2(lambda: (() -> String)?) { + if (lambda != null) { + lambda.invoke() + lambda() + } +} + +class A +operator fun A.invoke(): Unit = TODO() + +class Test3 { + val nullableCallableClass: A? = null + fun foo() { + if (nullableCallableClass != null) { + nullableCallableClass() + } + } +} + +fun test4(nullableCallableClass: A?){ + if (nullableCallableClass != null) { + nullableCallableClass() + } +} + +class B { + operator fun invoke(s: String): (() -> String)? = TODO() + operator fun invoke(): (() -> String) = TODO() +} + +class Test4 { + fun foo(a: B) { + if (a("") != null) { + a()() + a("")() + } + } +} + +fun test5(a: B) { + if (a("") != null) { + a()() + a("")() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt b/compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt new file mode 100644 index 00000000000..4f571815ff6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt @@ -0,0 +1,56 @@ +// ISSUE: KT-4113 +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +class Test1(val lambda: (() -> String)?) { + fun foo() { + if (lambda != null) { + lambda.invoke() + lambda() + } + } +} + +fun test2(lambda: (() -> String)?) { + if (lambda != null) { + lambda.invoke() + lambda() + } +} + +class A +operator fun A.invoke(): Unit = TODO() + +class Test3 { + val nullableCallableClass: A? = null + fun foo() { + if (nullableCallableClass != null) { + nullableCallableClass() + } + } +} + +fun test4(nullableCallableClass: A?){ + if (nullableCallableClass != null) { + nullableCallableClass() + } +} + +class B { + operator fun invoke(s: String): (() -> String)? = TODO() + operator fun invoke(): (() -> String) = TODO() +} + +class Test4 { + fun foo(a: B) { + if (a("") != null) { + a()() + a("")() + } + } +} + +fun test5(a: B) { + if (a("") != null) { + a()() + a("")() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.fir.kt new file mode 100644 index 00000000000..0b37b8f7fb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.fir.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-54443 +// WITH_STDLIB + +class A { + val b: Int? = 1 + val e: C? = C() +} + +class C { + val d: Int? = 2 +} + +fun test(a: A?) { + require(a?.b != null) + a.b.inc() +} + +fun test2(a: A?){ + require(a?.e?.d != null) + var k: C = a.e + var k2: Int = a.e.d + var k3: Int? = a.b +} + +fun test3(a:A?){ + val t = (a?.b != null) + require(t) + a.b.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt new file mode 100644 index 00000000000..80ce4069f3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-54443 +// WITH_STDLIB + +class A { + val b: Int? = 1 + val e: C? = C() +} + +class C { + val d: Int? = 2 +} + +fun test(a: A?) { + require(a?.b != null) + a.b.inc() +} + +fun test2(a: A?){ + require(a?.e?.d != null) + var k: C = a.e + var k2: Int = a.e.d + var k3: Int? = a.b +} + +fun test3(a:A?){ + val t = (a?.b != null) + require(t) + a.b.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.fir.kt new file mode 100644 index 00000000000..f07ba8d0f7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.fir.kt @@ -0,0 +1,35 @@ +// ISSUE: KT-25747 +fun test1() { + val nullableString: String? = "" + val savedSmartCastResult = nullableString != null + if (savedSmartCastResult) { + nullableString.length + } +} + +fun test2() { + var nullableAny: Any? = "" + val savedSmartCastResult = nullableAny is String + nullableAny = 10 + if (savedSmartCastResult) { + nullableAny.length + } +} + +class A { + val a: String? = "" +} +fun test3(a: A){ + val savedSmartCastResult = a.a != null + if(savedSmartCastResult) { + a.a.length + } +} + +fun test4() { + val nullableAny: Any? = "" + val savedSmartCastResult = (nullableAny!= null && nullableAny is String?) + if(savedSmartCastResult) { + nullableAny.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt b/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt new file mode 100644 index 00000000000..1cef395740f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt @@ -0,0 +1,35 @@ +// ISSUE: KT-25747 +fun test1() { + val nullableString: String? = "" + val savedSmartCastResult = nullableString != null + if (savedSmartCastResult) { + nullableString.length + } +} + +fun test2() { + var nullableAny: Any? = "" + val savedSmartCastResult = nullableAny is String + nullableAny = 10 + if (savedSmartCastResult) { + nullableAny.length + } +} + +class A { + val a: String? = "" +} +fun test3(a: A){ + val savedSmartCastResult = a.a != null + if(savedSmartCastResult) { + a.a.length + } +} + +fun test4() { + val nullableAny: Any? = "" + val savedSmartCastResult = (nullableAny!= null && nullableAny is String?) + if(savedSmartCastResult) { + nullableAny.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.fir.kt new file mode 100644 index 00000000000..f1d72639646 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.fir.kt @@ -0,0 +1,47 @@ +// ISSUE: KT-24779 +// WITH_STDLIB +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + +class C(val data: T) + +fun test1(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test2(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test3(x: C) { + val y = x.data + require(y is Number) + x.data.inc() + y.inc() +} + +fun test4(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test5(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test6(x: C) { + val y = x.data + require(y is Int) + x.data.inc() + y.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt b/compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt new file mode 100644 index 00000000000..fe58300d896 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt @@ -0,0 +1,47 @@ +// ISSUE: KT-24779 +// WITH_STDLIB +// DIAGNOSTICS: -DEBUG_INFO_SMARTCAST + +class C(val data: T) + +fun test1(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test2(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test3(x: C) { + val y = x.data + require(y is Number) + x.data.inc() + y.inc() +} + +fun test4(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test5(x: C) { + val y = x.data + require(y is String) + x.data.length + y.length +} + +fun test6(x: C) { + val y = x.data + require(y is Int) + x.data.inc() + y.inc() +} 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 2e3c9584eba..bc399803320 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 @@ -34156,6 +34156,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.kt"); } + @Test + @TestMetadata("binaryOperatorsWithJumps.kt") + public void testBinaryOperatorsWithJumps() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/binaryOperatorsWithJumps.kt"); + } + @Test @TestMetadata("classObjectMember.kt") public void testClassObjectMember() throws Exception { @@ -34168,6 +34174,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt"); } + @Test + @TestMetadata("comparisonOfBuiltInTypesUnderOr.kt") + public void testComparisonOfBuiltInTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfBuiltInTypesUnderOr.kt"); + } + + @Test + @TestMetadata("comparisonOfClassTypesUnderOr.kt") + public void testComparisonOfClassTypesUnderOr() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/comparisonOfClassTypesUnderOr.kt"); + } + @Test @TestMetadata("comparisonUnderAnd.kt") public void testComparisonUnderAnd() throws Exception { @@ -34720,6 +34738,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt"); } + @Test + @TestMetadata("nullableLambda.kt") + public void testNullableLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/nullableLambda.kt"); + } + @Test @TestMetadata("openInSealed.kt") public void testOpenInSealed() throws Exception { @@ -34750,6 +34774,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/safeAs.kt"); } + @Test + @TestMetadata("savedSmartcastResult.kt") + public void testSavedSmartcastResult() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt"); + } + @Test @TestMetadata("severalSmartCastsOnReified.kt") public void testSeveralSmartCastsOnReified() throws Exception { @@ -34888,6 +34918,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/typeInComparison.kt"); } + @Test + @TestMetadata("typeParameterWithBounds.kt") + public void testTypeParameterWithBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/typeParameterWithBounds.kt"); + } + @Test @TestMetadata("unstableToStable.kt") public void testUnstableToStable() throws Exception { @@ -35276,6 +35312,46 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts") + @TestDataPath("$PROJECT_ROOT") + public class LambdasWithContracts { + @Test + public void testAllFilesPresentInLambdasWithContracts() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("lambdaWithCallInPlace.kt") + public void testLambdaWithCallInPlace() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlace.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndBounds.kt") + public void testLambdaWithCallInPlaceAndBounds() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndBounds.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndDelegate.kt") + public void testLambdaWithCallInPlaceAndDelegate() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndDelegate.kt"); + } + + @Test + @TestMetadata("lambdaWithCallInPlaceAndOperators.kt") + public void testLambdaWithCallInPlaceAndOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithCallInPlaceAndOperators.kt"); + } + + @Test + @TestMetadata("lambdaWithImpliesContract.kt") + public void testLambdaWithImpliesContract() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/lambdasWithContracts/lambdaWithImpliesContract.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/smartCasts/loops") @TestDataPath("$PROJECT_ROOT") @@ -35795,6 +35871,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.kt"); } + @Test + @TestMetadata("childProperty.kt") + public void testChildProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/safecalls/childProperty.kt"); + } + @Test @TestMetadata("doubleCall.kt") public void testDoubleCall() throws Exception {