From 47d6236a2dc0bd1c9c9246c633e8b588a6a4b208 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 5 Apr 2022 17:19:06 +0300 Subject: [PATCH] [FIR] Support determining emptiness of an intersection type with type parameters' types --- ...CompilerTestFE10TestdataTestGenerated.java | 18 ++ ...irOldFrontendDiagnosticsTestGenerated.java | 174 ++++++++++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 174 ++++++++++++++++ .../kotlin/fir/types/ConeInferenceContext.kt | 14 +- .../jetbrains/kotlin/fir/types/TypeUtils.kt | 3 + .../fir/resolve/calls/ResolutionStages.kt | 5 +- .../fir/diagnostics/ConeSimpleDiagnostic.kt | 6 + .../kotlin/ir/types/IrTypeSystemContext.kt | 2 + .../ConstraintSystemCompletionContext.kt | 46 ---- .../components/ResultTypeResolver.kt | 25 ++- .../model/NewConstraintSystemImpl.kt | 9 +- .../calls/components/ResolutionParts.kt | 8 +- .../builderInference/stubTypes/intersect.kt | 8 +- ...romCovariantAndContravariantTypes.diag.txt | 2 +- .../postponedArgumentsAnalysis/basic.fir.kt | 2 +- .../tests/inference/kt45461.diag.txt | 2 +- .../diagnostics/tests/inference/kt45461_10.kt | 15 ++ .../tests/inference/kt45461_10.txt | 31 +++ .../tests/inference/kt45461_11.diag.txt | 3 + .../diagnostics/tests/inference/kt45461_11.kt | 17 ++ .../tests/inference/kt45461_11.txt | 38 ++++ .../tests/inference/kt45461_12.diag.txt | 7 + .../tests/inference/kt45461_12.fir.kt | 13 ++ .../diagnostics/tests/inference/kt45461_12.kt | 13 ++ .../tests/inference/kt45461_12.txt | 24 +++ .../diagnostics/tests/inference/kt45461_13.kt | 15 ++ .../tests/inference/kt45461_13.txt | 31 +++ .../diagnostics/tests/inference/kt45461_14.kt | 16 ++ .../tests/inference/kt45461_14.txt | 37 ++++ .../tests/inference/kt45461_15.diag.txt | 6 + .../tests/inference/kt45461_15.fir.kt | 15 ++ .../diagnostics/tests/inference/kt45461_15.kt | 15 ++ .../tests/inference/kt45461_15.txt | 31 +++ .../diagnostics/tests/inference/kt45461_16.kt | 15 ++ .../tests/inference/kt45461_16.txt | 31 +++ .../diagnostics/tests/inference/kt45461_17.kt | 15 ++ .../tests/inference/kt45461_17.txt | 31 +++ .../diagnostics/tests/inference/kt45461_18.kt | 13 ++ .../tests/inference/kt45461_18.txt | 25 +++ .../tests/inference/kt45461_19.diag.txt | 6 + .../tests/inference/kt45461_19.fir.kt | 14 ++ .../diagnostics/tests/inference/kt45461_19.kt | 14 ++ .../tests/inference/kt45461_19.txt | 32 +++ .../tests/inference/kt45461_2.diag.txt | 2 +- .../diagnostics/tests/inference/kt45461_20.kt | 14 ++ .../tests/inference/kt45461_20.txt | 32 +++ .../tests/inference/kt45461_21.diag.txt | 6 + .../tests/inference/kt45461_21.fir.kt | 14 ++ .../diagnostics/tests/inference/kt45461_21.kt | 14 ++ .../tests/inference/kt45461_21.txt | 32 +++ .../diagnostics/tests/inference/kt45461_22.kt | 13 ++ .../tests/inference/kt45461_22.txt | 25 +++ .../diagnostics/tests/inference/kt45461_23.kt | 13 ++ .../tests/inference/kt45461_23.txt | 25 +++ .../tests/inference/kt45461_24.diag.txt | 9 + .../tests/inference/kt45461_24.fir.kt | 13 ++ .../diagnostics/tests/inference/kt45461_24.kt | 13 ++ .../tests/inference/kt45461_24.txt | 25 +++ .../tests/inference/kt45461_25.diag.txt | 3 + .../tests/inference/kt45461_25.fir.kt | 12 ++ .../diagnostics/tests/inference/kt45461_25.kt | 12 ++ .../tests/inference/kt45461_25.txt | 18 ++ .../tests/inference/kt45461_26.diag.txt | 4 + .../tests/inference/kt45461_26.fir.kt | 14 ++ .../diagnostics/tests/inference/kt45461_26.kt | 14 ++ .../tests/inference/kt45461_26.txt | 25 +++ .../diagnostics/tests/inference/kt45461_27.kt | 13 ++ .../tests/inference/kt45461_27.txt | 25 +++ .../tests/inference/kt45461_28.fir.kt | 12 ++ .../diagnostics/tests/inference/kt45461_28.kt | 12 ++ .../tests/inference/kt45461_28.txt | 25 +++ .../tests/inference/kt45461_5.diag.txt | 5 +- .../tests/inference/kt45461_5.fir.kt | 4 +- .../diagnostics/tests/inference/kt45461_5.kt | 2 +- .../diagnostics/tests/inference/kt45461_5.txt | 2 +- .../diagnostics/tests/inference/kt45461_6.kt | 11 + .../diagnostics/tests/inference/kt45461_6.txt | 18 ++ .../diagnostics/tests/inference/kt45461_7.kt | 11 + .../diagnostics/tests/inference/kt45461_7.txt | 18 ++ .../tests/inference/kt45461_8.diag.txt | 9 + .../tests/inference/kt45461_8.fir.kt | 13 ++ .../diagnostics/tests/inference/kt45461_8.kt | 13 ++ .../diagnostics/tests/inference/kt45461_8.txt | 25 +++ .../tests/inference/kt45461_9.diag.txt | 7 + .../tests/inference/kt45461_9.fir.kt | 13 ++ .../diagnostics/tests/inference/kt45461_9.kt | 13 ++ .../diagnostics/tests/inference/kt45461_9.txt | 25 +++ .../tests/inference/kt48765.diag.txt | 2 +- .../tests/inference/kt48935.diag.txt | 5 +- .../tests/inference/kt49661.diag.txt | 2 +- .../nullableEmptyIntersection.fir.kt | 7 + .../upperBounds/nullableEmptyIntersection.kt | 7 + .../upperBounds/nullableEmptyIntersection.txt | 5 + .../test/runners/DiagnosticTestGenerated.java | 174 ++++++++++++++++ .../kotlin/types/EmptyIntersectionTypeKind.kt | 12 ++ .../kotlin/types/model/TypeSystemContext.kt | 197 ++++++++++++++++-- .../types/checker/ClassicTypeSystemContext.kt | 16 +- 97 files changed, 1970 insertions(+), 106 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_10.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_10.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_11.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_11.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_11.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_12.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_12.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_12.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_12.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_13.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_13.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_14.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_14.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_15.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_15.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_15.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_15.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_16.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_16.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_17.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_17.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_18.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_18.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_19.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_19.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_19.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_19.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_20.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_20.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_21.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_21.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_21.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_21.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_22.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_22.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_23.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_23.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_24.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_24.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_24.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_24.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_25.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_25.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_25.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_25.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_26.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_26.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_26.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_26.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_27.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_27.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_28.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_28.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_28.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_6.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_6.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_7.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_7.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_8.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_8.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_8.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_8.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_9.diag.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_9.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_9.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461_9.txt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.txt create mode 100644 core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index e55f0b0f6e5..3c99d379ac2 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -13888,6 +13888,24 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt"); } + @Test + @TestMetadata("kt48935_2.kt") + public void testKt48935_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt"); + } + + @Test + @TestMetadata("kt48935_3.kt") + public void testKt48935_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt"); + } + + @Test + @TestMetadata("kt48935_4.kt") + public void testKt48935_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt"); + } + @Test @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index e9e11b6b8b0..c18d273afa4 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -13840,12 +13840,126 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt"); } + @Test + @TestMetadata("kt45461_10.kt") + public void testKt45461_10() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_10.kt"); + } + + @Test + @TestMetadata("kt45461_11.kt") + public void testKt45461_11() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_11.kt"); + } + + @Test + @TestMetadata("kt45461_12.kt") + public void testKt45461_12() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_12.kt"); + } + + @Test + @TestMetadata("kt45461_13.kt") + public void testKt45461_13() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_13.kt"); + } + + @Test + @TestMetadata("kt45461_14.kt") + public void testKt45461_14() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_14.kt"); + } + + @Test + @TestMetadata("kt45461_15.kt") + public void testKt45461_15() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_15.kt"); + } + + @Test + @TestMetadata("kt45461_16.kt") + public void testKt45461_16() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_16.kt"); + } + + @Test + @TestMetadata("kt45461_17.kt") + public void testKt45461_17() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_17.kt"); + } + + @Test + @TestMetadata("kt45461_18.kt") + public void testKt45461_18() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_18.kt"); + } + + @Test + @TestMetadata("kt45461_19.kt") + public void testKt45461_19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_19.kt"); + } + @Test @TestMetadata("kt45461_2.kt") public void testKt45461_2() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt"); } + @Test + @TestMetadata("kt45461_20.kt") + public void testKt45461_20() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_20.kt"); + } + + @Test + @TestMetadata("kt45461_21.kt") + public void testKt45461_21() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_21.kt"); + } + + @Test + @TestMetadata("kt45461_22.kt") + public void testKt45461_22() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_22.kt"); + } + + @Test + @TestMetadata("kt45461_23.kt") + public void testKt45461_23() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_23.kt"); + } + + @Test + @TestMetadata("kt45461_24.kt") + public void testKt45461_24() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_24.kt"); + } + + @Test + @TestMetadata("kt45461_25.kt") + public void testKt45461_25() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_25.kt"); + } + + @Test + @TestMetadata("kt45461_26.kt") + public void testKt45461_26() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_26.kt"); + } + + @Test + @TestMetadata("kt45461_27.kt") + public void testKt45461_27() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_27.kt"); + } + + @Test + @TestMetadata("kt45461_28.kt") + public void testKt45461_28() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_28.kt"); + } + @Test @TestMetadata("kt45461_3.kt") public void testKt45461_3() throws Exception { @@ -13864,6 +13978,30 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt"); } + @Test + @TestMetadata("kt45461_6.kt") + public void testKt45461_6() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_6.kt"); + } + + @Test + @TestMetadata("kt45461_7.kt") + public void testKt45461_7() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_7.kt"); + } + + @Test + @TestMetadata("kt45461_8.kt") + public void testKt45461_8() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_8.kt"); + } + + @Test + @TestMetadata("kt45461_9.kt") + public void testKt45461_9() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_9.kt"); + } + @Test @TestMetadata("kt46515.kt") public void testKt46515() throws Exception { @@ -13888,6 +14026,36 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt"); } + @Test + @TestMetadata("kt48935_2.kt") + public void testKt48935_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt"); + } + + @Test + @TestMetadata("kt48935_3.kt") + public void testKt48935_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt"); + } + + @Test + @TestMetadata("kt48935_4.kt") + public void testKt48935_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt"); + } + + @Test + @TestMetadata("kt48935_5.kt") + public void testKt48935_5() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_5.kt"); + } + + @Test + @TestMetadata("kt48935_6.kt") + public void testKt48935_6() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_6.kt"); + } + @Test @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { @@ -16459,6 +16627,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt"); } + @Test + @TestMetadata("nullableEmptyIntersection.kt") + public void testNullableEmptyIntersection() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt"); + } + @Test @TestMetadata("typeParameterAsUpperBound.kt") public void testTypeParameterAsUpperBound() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index e9eb435b3e3..8123178951d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -13840,12 +13840,126 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt"); } + @Test + @TestMetadata("kt45461_10.kt") + public void testKt45461_10() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_10.kt"); + } + + @Test + @TestMetadata("kt45461_11.kt") + public void testKt45461_11() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_11.kt"); + } + + @Test + @TestMetadata("kt45461_12.kt") + public void testKt45461_12() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_12.kt"); + } + + @Test + @TestMetadata("kt45461_13.kt") + public void testKt45461_13() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_13.kt"); + } + + @Test + @TestMetadata("kt45461_14.kt") + public void testKt45461_14() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_14.kt"); + } + + @Test + @TestMetadata("kt45461_15.kt") + public void testKt45461_15() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_15.kt"); + } + + @Test + @TestMetadata("kt45461_16.kt") + public void testKt45461_16() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_16.kt"); + } + + @Test + @TestMetadata("kt45461_17.kt") + public void testKt45461_17() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_17.kt"); + } + + @Test + @TestMetadata("kt45461_18.kt") + public void testKt45461_18() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_18.kt"); + } + + @Test + @TestMetadata("kt45461_19.kt") + public void testKt45461_19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_19.kt"); + } + @Test @TestMetadata("kt45461_2.kt") public void testKt45461_2() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt"); } + @Test + @TestMetadata("kt45461_20.kt") + public void testKt45461_20() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_20.kt"); + } + + @Test + @TestMetadata("kt45461_21.kt") + public void testKt45461_21() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_21.kt"); + } + + @Test + @TestMetadata("kt45461_22.kt") + public void testKt45461_22() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_22.kt"); + } + + @Test + @TestMetadata("kt45461_23.kt") + public void testKt45461_23() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_23.kt"); + } + + @Test + @TestMetadata("kt45461_24.kt") + public void testKt45461_24() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_24.kt"); + } + + @Test + @TestMetadata("kt45461_25.kt") + public void testKt45461_25() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_25.kt"); + } + + @Test + @TestMetadata("kt45461_26.kt") + public void testKt45461_26() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_26.kt"); + } + + @Test + @TestMetadata("kt45461_27.kt") + public void testKt45461_27() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_27.kt"); + } + + @Test + @TestMetadata("kt45461_28.kt") + public void testKt45461_28() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_28.kt"); + } + @Test @TestMetadata("kt45461_3.kt") public void testKt45461_3() throws Exception { @@ -13864,6 +13978,30 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt"); } + @Test + @TestMetadata("kt45461_6.kt") + public void testKt45461_6() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_6.kt"); + } + + @Test + @TestMetadata("kt45461_7.kt") + public void testKt45461_7() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_7.kt"); + } + + @Test + @TestMetadata("kt45461_8.kt") + public void testKt45461_8() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_8.kt"); + } + + @Test + @TestMetadata("kt45461_9.kt") + public void testKt45461_9() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_9.kt"); + } + @Test @TestMetadata("kt46515.kt") public void testKt46515() throws Exception { @@ -13888,6 +14026,36 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt"); } + @Test + @TestMetadata("kt48935_2.kt") + public void testKt48935_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt"); + } + + @Test + @TestMetadata("kt48935_3.kt") + public void testKt48935_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt"); + } + + @Test + @TestMetadata("kt48935_4.kt") + public void testKt48935_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt"); + } + + @Test + @TestMetadata("kt48935_5.kt") + public void testKt48935_5() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_5.kt"); + } + + @Test + @TestMetadata("kt48935_6.kt") + public void testKt48935_6() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_6.kt"); + } + @Test @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { @@ -16459,6 +16627,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt"); } + @Test + @TestMetadata("nullableEmptyIntersection.kt") + public void testNullableEmptyIntersection() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt"); + } + @Test @TestMetadata("typeParameterAsUpperBound.kt") public void testTypeParameterAsUpperBound() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index a0559dfad7d..453c629d924 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor +import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap import org.jetbrains.kotlin.fir.resolve.substitution.NoSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.createTypeSubstitutorByTypeConstructor import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag @@ -272,11 +273,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return ConeStubTypeForTypeVariableInSubtyping(typeVariable, ConeNullability.create(typeVariable.defaultType().isMarkedNullable())) } - override fun KotlinTypeMarker.isFinal(): Boolean { - require(this is ConeKotlinType) - return !this.canHaveSubtypes(session) - } - override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker { require(this is ConeKotlinType) return withAttributes(ConeAttributes.Empty) @@ -388,6 +384,13 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return this is ConeCapturedTypeConstructor } + override fun KotlinTypeMarker.eraseContainingTypeParameters(): KotlinTypeMarker { + val erasedTypeParameters = this.extractTypeParameters() + .map { (it as ConeTypeParameterLookupTag).typeParameterSymbol } + .eraseToUpperBoundsAssociated(session, intersectUpperBounds = true, eraseRecursively = true) + return ConeSubstitutorByMap(erasedTypeParameters, session).safeSubstitute(this) + } + override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean { return this.getTypeParameterClassifier() != null } @@ -477,7 +480,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return this.lowerBoundIfFlexible().safeAs()?.isExtensionFunctionType(session) == true } - @OptIn(ExperimentalStdlibApi::class) override fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List { val builtInFunctionalType = getFunctionalTypeFromSupertypes().cast() return buildList { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index c8b78173e55..5085dfab1c1 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -726,6 +726,9 @@ private fun SimpleTypeMarker.eraseArgumentsDeeply( intersectUpperBounds: Boolean, ): ConeKotlinType = with(typeContext) { replaceArgumentsDeeply { typeArgument -> + if (typeArgument.isStarProjection()) + return@replaceArgumentsDeeply typeArgument + val typeConstructor = typeArgument.getType().typeConstructor().takeIf { it.isTypeParameterTypeConstructor() } ?: return@replaceArgumentsDeeply typeArgument diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index 7c8b3fdc8e0..b8cc70fb4ef 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.types.AbstractNullabilityChecker import org.jetbrains.kotlin.types.TypeApproximatorConfiguration +import org.jetbrains.kotlin.types.isDefinitelyEmpty import org.jetbrains.kotlin.util.OperatorNameConventions abstract class ResolutionStage { @@ -579,12 +580,12 @@ internal object CheckLowPriorityInOverloadResolution : CheckerStage() { internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() { override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) = with(candidate.system.asConstraintSystemCompleterContext()) { - val typeVariables = candidate.system.notFixedTypeVariables.values + val typeVariables = candidate.system.notFixedTypeVariables.values.takeIf { it.isNotEmpty() } ?: return for (variableWithConstraints in typeVariables) { val upperTypes = variableWithConstraints.constraints.extractUpperTypes() - if (upperTypes.isEmptyIntersection()) { + if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) { sink.yieldDiagnostic( @Suppress("UNCHECKED_CAST") InferredEmptyIntersectionDiagnostic( diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt index 08925a58772..a4f75767cf1 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.diagnostics import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.name.Name class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind = DiagnosticKind.Other) : ConeDiagnostic @@ -29,6 +30,11 @@ class ConeAmbiguousSuper(val candidateTypes: List) : ConeDiagnos get() = "Ambiguous supertype" } +class ConeRecursiveTypeParameterDuringErasureError(val typeParameterName: Name) : ConeDiagnostic { + override val reason: String + get() = "self-recursive type parameter $typeParameterName" +} + enum class DiagnosticKind { Syntax, ExpressionExpected, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index 854c640663b..cf28656c9dc 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -172,6 +172,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon return (this as? IrClassSymbol)?.owner?.isInterface == true } + override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean = this is IrTypeParameterSymbol + override fun TypeParameterMarker.getVariance() = (this as IrTypeParameterSymbol).owner.variance.convertVariance() private fun getSuperTypes(typeParameterMarker: TypeParameterMarker) = (typeParameterMarker as IrTypeParameterSymbol).owner.superTypes diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt index 13a048089b1..2e4b9b68d0e 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt @@ -8,11 +8,9 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder -import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker -import org.jetbrains.kotlin.types.AbstractTypeChecker.isRelatedBySubtypingTo import org.jetbrains.kotlin.types.model.* abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Context, ResultTypeResolver.Context { @@ -37,50 +35,6 @@ abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Contex abstract fun couldBeResolvedWithUnrestrictedBuilderInference(): Boolean abstract fun processForkConstraints() - private fun TypeConstructorMarker.isDefinitelyClass() = isClassTypeConstructor() && !isInterface() - - private fun KotlinTypeMarker.containsTypeParameter() = contains { it.typeConstructor().isTypeParameterTypeConstructor() } - - fun Collection.isEmptyIntersection(constraintSystem: NewConstraintSystem?): Boolean { - val indexedComponents = withIndex() - return indexedComponents.any firstTypes@{ (i, first) -> - val firstTypeConstructor = first.typeConstructor() - indexedComponents.any secondTypes@{ (j, second) -> - if (i >= j) return@secondTypes false - - val secondTypeConstructor = second.typeConstructor() - - if (!firstTypeConstructor.isDefinitelyClass() && !firstTypeConstructor.isTypeParameterTypeConstructor()) - return@secondTypes false - if (!secondTypeConstructor.isDefinitelyClass() && !secondTypeConstructor.isTypeParameterTypeConstructor()) - return@secondTypes false - - if (!first.containsTypeParameter() && !second.containsTypeParameter()) { - return@secondTypes !isRelatedBySubtypingTo(this@ConstraintSystemCompletionContext, first, second) - } - - if (constraintSystem == null) return false - - val completerContext = constraintSystem.asConstraintSystemCompleterContext() - val substitutionMap = completerContext.allTypeVariables.entries.associate { (key, value) -> - val typeParameter = (key as TypeVariableTypeConstructorMarker).typeParameter - require(typeParameter != null) { - "Constraint system for checking type parameters for intersection emptiness" + - "should be build with type variables which refer to those type parameters" - } - typeParameter.getTypeConstructor() to value.defaultType() - } - val substitutor = typeSubstitutorByTypeConstructor(substitutionMap) - - completerContext.getBuilder().addSubtypeConstraint( - substitutor.safeSubstitute(first), substitutor.safeSubstitute(second), TypeParametersIntersectionEmptyCheckingPosition - ) - - constraintSystem.hasContradiction - } - } - } - fun analyzeArgumentWithFixedParameterTypes( languageVersionSettings: LanguageVersionSettings, postponedArguments: List, diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt index 640edddddf1..ab939c725fe 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt @@ -44,7 +44,6 @@ class ResultTypeResolver( return createCapturedStarProjectionForSelfType(typeVariableConstructor, typesForRecursiveTypeParameters) } - @OptIn(ExperimentalStdlibApi::class) private fun Context.getDefaultType( direction: ResolveDirection, constraints: List, @@ -241,10 +240,13 @@ class ResultTypeResolver( } } - private fun Context.findSuperType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? { - val upperConstraints = - variableWithConstraints.constraints.filter { it.kind == ConstraintKind.UPPER && this@findSuperType.isProperTypeForFixation(it.type) } - if (upperConstraints.isNotEmpty()) { + private fun Context.computeUpperType(upperConstraints: List): KotlinTypeMarker { + val isInferringIntoEmptyIntersectionEnabled = + languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection) + + // TODO: Remove this after stopping support of disabling `ForbidInferringTypeVariablesIntoEmptyIntersection` + // If `ForbidInferringTypeVariablesIntoEmptyIntersection` is enabled, we do the corresponding checks during resolution and completion + return if (!isInferringIntoEmptyIntersectionEnabled) { val intersectionUpperType = intersectTypes(upperConstraints.map { it.type }) val resultIsActuallyIntersection = intersectionUpperType.typeConstructor().isIntersection() @@ -268,12 +270,25 @@ class ResultTypeResolver( val filteredUpperConstraints = upperConstraints.filterNot { it.isExpectedTypePosition() }.map { it.type } if (filteredUpperConstraints.isNotEmpty()) intersectTypes(filteredUpperConstraints) else intersectionUpperType } else intersectionUpperType + upperType + } else { + intersectTypes(upperConstraints.map { it.type }) + } + } + + private fun Context.findSuperType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? { + val upperConstraints = + variableWithConstraints.constraints.filter { it.kind == ConstraintKind.UPPER && this@findSuperType.isProperTypeForFixation(it.type) } + + if (upperConstraints.isNotEmpty()) { + val upperType = computeUpperType(upperConstraints) return typeApproximator.approximateToSubType( upperType, TypeApproximatorConfiguration.InternalTypesApproximation ) ?: upperType } + return null } diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index df64d7df10f..57e59b077b5 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.* import org.jetbrains.kotlin.types.AbstractTypeApproximator import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.TypeApproximatorConfiguration +import org.jetbrains.kotlin.types.isDefinitelyEmpty import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartSet @@ -443,12 +444,14 @@ class NewConstraintSystemImpl( val intersectionTypeConstructor = resultType.typeConstructor().takeIf { it is IntersectionTypeConstructorMarker } ?: return val isInferredEmptyIntersectionForbidden = languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection) - val intersectionComponents = intersectionTypeConstructor.supertypes() + val upperTypes = intersectionTypeConstructor.supertypes() - if (intersectionComponents.isEmptyIntersection()) { + if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) { + // Remove existing errors from resolution stage because a completion error is more precise + storage.errors.removeIf { it is InferredEmptyIntersectionError || it is InferredEmptyIntersectionWarning } val errorFactory = if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning - addError(errorFactory(intersectionComponents, variable)) + addError(errorFactory(upperTypes, variable)) } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 5a4ecbc47c3..26e61061d49 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -26,9 +26,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastI import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.error.ErrorUtils -import org.jetbrains.kotlin.types.model.KotlinTypeMarker -import org.jetbrains.kotlin.types.model.TypeConstructorMarker -import org.jetbrains.kotlin.types.model.typeConstructor +import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.types.typeUtil.* import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.addToStdlib.cast @@ -903,12 +901,12 @@ internal object CheckContextReceiversResolutionPart : ResolutionPart() { internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() { override fun ResolutionCandidate.process(workIndex: Int) = with(getSystem().asConstraintSystemCompleterContext()) { - val typeVariables = getSystem().getBuilder().currentStorage().notFixedTypeVariables.values + val typeVariables = getSystem().getBuilder().currentStorage().notFixedTypeVariables.values.takeIf { it.isNotEmpty() } ?: return for (variableWithConstraints in typeVariables) { val upperTypes = variableWithConstraints.constraints.extractUpperTypes() - if (upperTypes.isEmptyIntersection()) { + if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) { val isInferredEmptyIntersectionForbidden = callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection) diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt index 4b92674c263..9224ad1ebce 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt @@ -38,10 +38,10 @@ fun test() { build2 { emit(1) - intersect(this@build.getIn(), getIn()) - intersect(getIn(), Test.foo(this@build.getIn())) - intersect(Test.foo(this@build.getIn()), Test.foo(getIn())) - intersect(Test.foo(getIn()), this@build.getIn()) + intersect(this@build.getIn(), getIn()) + intersect(getIn(), Test.foo(this@build.getIn())) + intersect(Test.foo(this@build.getIn()), Test.foo(getIn())) + intersect(Test.foo(getIn()), this@build.getIn()) "" } "" diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.diag.txt b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.diag.txt index 2b0d901c1af..1c0121e86fc 100644 --- a/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.diag.txt @@ -7,6 +7,6 @@ fun genericIn(x: In) {} /selectFromCovariantAndContravariantTypes.kt:13:20: warning: parameter 'x' is never used fun genericOut(x: Out) {} ^ -/selectFromCovariantAndContravariantTypes.kt:16:5: warning: type argument for a type parameter V can't be inferred because it's upper bounded by incompatible types: A, B. This will become an error in Kotlin 1.8 +/selectFromCovariantAndContravariantTypes.kt:16:5: warning: type argument for a type parameter V can't be inferred because it's upper bounded by incompatible types: A, B. This will become an error in Kotlin 1.9 genericIn(select(a, b)) ^ diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt index 59bbc661e66..e70e84fe24c 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt @@ -70,7 +70,7 @@ fun main() { select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2 { x: Int -> x })) select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2(::takeInt))) select(id1 { x: Inv -> TODO() }, id1 { ")!>it.x.inv() }, id1 { x: Inv -> TODO() }) - select(id1 { & Inv")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) + select(id1 { & Inv")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) select(id(id2 { it.inv() }), id(id { x: Int -> x })) // Disambiguating callable references by other callable references without overloads diff --git a/compiler/testData/diagnostics/tests/inference/kt45461.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461.diag.txt index 67f32502222..01e1b9d13de 100644 --- a/compiler/testData/diagnostics/tests/inference/kt45461.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/kt45461.diag.txt @@ -1,6 +1,6 @@ /kt45461.kt:5:25: warning: parameter 'foo' is never used fun takeFoo(foo: Foo) {} ^ -/kt45461.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, Int. This will become an error in Kotlin 1.8 +/kt45461.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, Int. This will become an error in Kotlin 1.9 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_10.kt b/compiler/testData/diagnostics/tests/inference/kt45461_10.kt new file mode 100644 index 00000000000..eb2e36f1f0d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_10.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Out + +interface A + +fun , L : N, N: A> main() { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_10.txt b/compiler/testData/diagnostics/tests/inference/kt45461_10.txt new file mode 100644 index 00000000000..37716fba8f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_10.txt @@ -0,0 +1,31 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : A> main(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_11.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_11.diag.txt new file mode 100644 index 00000000000..27a8145ebd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_11.diag.txt @@ -0,0 +1,3 @@ +/kt45461_11.kt:6:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_11.kt b/compiler/testData/diagnostics/tests/inference/kt45461_11.kt new file mode 100644 index 00000000000..819fc73f0c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_11.kt @@ -0,0 +1,17 @@ +// FIR_IDENTICAL +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Out + +interface A +open class B + +fun , L : N, N: A> main() { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_11.txt b/compiler/testData/diagnostics/tests/inference/kt45461_11.txt new file mode 100644 index 00000000000..60bf4ebae58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_11.txt @@ -0,0 +1,38 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : A> main(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_12.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_12.diag.txt new file mode 100644 index 00000000000..4016201980a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_12.diag.txt @@ -0,0 +1,7 @@ +/kt45461_12.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_12.kt:12:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.8 + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ + diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_12.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_12.fir.kt new file mode 100644 index 00000000000..5ab681631cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_12.fir.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +interface A + +fun main() where N: A, N: Number { + val foo = Foo() + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_12.kt b/compiler/testData/diagnostics/tests/inference/kt45461_12.kt new file mode 100644 index 00000000000..7dad9ad84c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_12.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +interface A + +fun main() where N: A, N: Number { + val foo = Foo() + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_12.txt b/compiler/testData/diagnostics/tests/inference/kt45461_12.txt new file mode 100644 index 00000000000..bb3ea4864ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_12.txt @@ -0,0 +1,24 @@ +package + +public fun main(): kotlin.Unit where N : kotlin.Number + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_13.kt b/compiler/testData/diagnostics/tests/inference/kt45461_13.kt new file mode 100644 index 00000000000..07a7d423662 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_13.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +interface A + +class Out + +fun main() where N: Out { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_13.txt b/compiler/testData/diagnostics/tests/inference/kt45461_13.txt new file mode 100644 index 00000000000..2f5eda5a044 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_13.txt @@ -0,0 +1,31 @@ +package + +public fun > main(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_14.kt b/compiler/testData/diagnostics/tests/inference/kt45461_14.kt new file mode 100644 index 00000000000..0fe20523d2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_14.kt @@ -0,0 +1,16 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Out + +interface A +interface B + +fun > main() { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_14.txt b/compiler/testData/diagnostics/tests/inference/kt45461_14.txt new file mode 100644 index 00000000000..561c930745d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_14.txt @@ -0,0 +1,37 @@ +package + +public fun > main(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_15.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_15.diag.txt new file mode 100644 index 00000000000..6d2ac79d1ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_15.diag.txt @@ -0,0 +1,6 @@ +/kt45461_15.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_15.kt:14:21: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv, K. This will become an error in Kotlin 1.9 + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_15.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_15.fir.kt new file mode 100644 index 00000000000..624b1dbe7dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_15.fir.kt @@ -0,0 +1,15 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +interface A + +fun , T> main() where T: A, T: Number { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_15.kt b/compiler/testData/diagnostics/tests/inference/kt45461_15.kt new file mode 100644 index 00000000000..b079206960c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_15.kt @@ -0,0 +1,15 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +interface A + +fun , T> main() where T: A, T: Number { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_15.txt b/compiler/testData/diagnostics/tests/inference/kt45461_15.txt new file mode 100644 index 00000000000..0046f7c7006 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_15.txt @@ -0,0 +1,31 @@ +package + +public fun , /*1*/ T : A> main(): kotlin.Unit where T : kotlin.Number + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_16.kt b/compiler/testData/diagnostics/tests/inference/kt45461_16.kt new file mode 100644 index 00000000000..977ce4ae8d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_16.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +interface A + +fun , T> main() where T: A, T: Number { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_16.txt b/compiler/testData/diagnostics/tests/inference/kt45461_16.txt new file mode 100644 index 00000000000..0046f7c7006 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_16.txt @@ -0,0 +1,31 @@ +package + +public fun , /*1*/ T : A> main(): kotlin.Unit where T : kotlin.Number + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_17.kt b/compiler/testData/diagnostics/tests/inference/kt45461_17.kt new file mode 100644 index 00000000000..3e7aff2cdfa --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_17.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +interface A + +fun , T> main() where T: String { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_17.txt b/compiler/testData/diagnostics/tests/inference/kt45461_17.txt new file mode 100644 index 00000000000..d39a08e3d7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_17.txt @@ -0,0 +1,31 @@ +package + +public fun , /*1*/ T : kotlin.String> main(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_18.kt b/compiler/testData/diagnostics/tests/inference/kt45461_18.kt new file mode 100644 index 00000000000..93e72cff85f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_18.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Out + +fun , L : N, N: Number> main() { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_18.txt b/compiler/testData/diagnostics/tests/inference/kt45461_18.txt new file mode 100644 index 00000000000..3ee1adc172f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_18.txt @@ -0,0 +1,25 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : kotlin.Number> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_19.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_19.diag.txt new file mode 100644 index 00000000000..bcaeb0f8aec --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_19.diag.txt @@ -0,0 +1,6 @@ +/kt45461_19.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_19.kt:13:26: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Out>, K. This will become an error in Kotlin 1.9 + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_19.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_19.fir.kt new file mode 100644 index 00000000000..5c83a411f5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_19.fir.kt @@ -0,0 +1,14 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Out +class Inv + +fun , L : N, N: Inv> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_19.kt b/compiler/testData/diagnostics/tests/inference/kt45461_19.kt new file mode 100644 index 00000000000..81eedce1c54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_19.kt @@ -0,0 +1,14 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Out +class Inv + +fun , L : N, N: Inv> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_19.txt b/compiler/testData/diagnostics/tests/inference/kt45461_19.txt new file mode 100644 index 00000000000..b889e2c0f2c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_19.txt @@ -0,0 +1,32 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : Inv> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_2.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_2.diag.txt index 59339fb658b..2269aabe174 100644 --- a/compiler/testData/diagnostics/tests/inference/kt45461_2.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/kt45461_2.diag.txt @@ -4,7 +4,7 @@ /kt45461_2.kt:8:10: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined fun main() { ^ -/kt45461_2.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.8 +/kt45461_2.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.9 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_20.kt b/compiler/testData/diagnostics/tests/inference/kt45461_20.kt new file mode 100644 index 00000000000..18e1fdd5a25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_20.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class In +class Inv + +fun , L : N, N: Inv> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_20.txt b/compiler/testData/diagnostics/tests/inference/kt45461_20.txt new file mode 100644 index 00000000000..86bfbcb3fa0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_20.txt @@ -0,0 +1,32 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : Inv> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class In { + public constructor In() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_21.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_21.diag.txt new file mode 100644 index 00000000000..80aeb9550ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_21.diag.txt @@ -0,0 +1,6 @@ +/kt45461_21.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_21.kt:13:25: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: In>, K. This will become an error in Kotlin 1.9 + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_21.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_21.fir.kt new file mode 100644 index 00000000000..e61baf024db --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_21.fir.kt @@ -0,0 +1,14 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class In +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_21.kt b/compiler/testData/diagnostics/tests/inference/kt45461_21.kt new file mode 100644 index 00000000000..218de01bd68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_21.kt @@ -0,0 +1,14 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class In +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_21.txt b/compiler/testData/diagnostics/tests/inference/kt45461_21.txt new file mode 100644 index 00000000000..5acd3c00688 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_21.txt @@ -0,0 +1,32 @@ +package + +public fun >> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class In { + public constructor In() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_22.kt b/compiler/testData/diagnostics/tests/inference/kt45461_22.kt new file mode 100644 index 00000000000..cbb62bc1485 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_22.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_22.txt b/compiler/testData/diagnostics/tests/inference/kt45461_22.txt new file mode 100644 index 00000000000..e25666c39bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_22.txt @@ -0,0 +1,25 @@ +package + +public fun >> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_23.kt b/compiler/testData/diagnostics/tests/inference/kt45461_23.kt new file mode 100644 index 00000000000..419fc423ead --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_23.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_23.txt b/compiler/testData/diagnostics/tests/inference/kt45461_23.txt new file mode 100644 index 00000000000..e25666c39bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_23.txt @@ -0,0 +1,25 @@ +package + +public fun >> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_24.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_24.diag.txt new file mode 100644 index 00000000000..9b08fd4a468 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_24.diag.txt @@ -0,0 +1,9 @@ +/kt45461_24.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_24.kt:10:10: warning: 'Inv>' is a final type, and thus a value of the type parameter is predetermined +fun >> main() { + ^ +/kt45461_24.kt:12:35: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv>, K. This will become an error in Kotlin 1.9 + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_24.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_24.fir.kt new file mode 100644 index 00000000000..3c93ffe315f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_24.fir.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun Inv>> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_24.kt b/compiler/testData/diagnostics/tests/inference/kt45461_24.kt new file mode 100644 index 00000000000..95444ee4403 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_24.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun Inv>> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_24.txt b/compiler/testData/diagnostics/tests/inference/kt45461_24.txt new file mode 100644 index 00000000000..ea224f2d07b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_24.txt @@ -0,0 +1,25 @@ +package + +public fun >> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_25.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_25.diag.txt new file mode 100644 index 00000000000..3cbaaa007a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_25.diag.txt @@ -0,0 +1,3 @@ +/kt45461_25.kt:11:34: error: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K, Float + val x: Float = Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_25.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_25.fir.kt new file mode 100644 index 00000000000..1363fe122a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_25.fir.kt @@ -0,0 +1,12 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection +class Foo + +class Bar { + fun takeFoo(foo: Foo): S = null as S +} + +fun Int> main() { + val foo = Foo() + val x: Float = Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_25.kt b/compiler/testData/diagnostics/tests/inference/kt45461_25.kt new file mode 100644 index 00000000000..dbce722b317 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_25.kt @@ -0,0 +1,12 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection +class Foo + +class Bar { + fun takeFoo(foo: Foo): S = null as S +} + +fun Int> main() { + val foo = Foo() + val x: Float = Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_25.txt b/compiler/testData/diagnostics/tests/inference/kt45461_25.txt new file mode 100644 index 00000000000..dd11e7589de --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_25.txt @@ -0,0 +1,18 @@ +package + +public fun main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): S + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_26.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_26.diag.txt new file mode 100644 index 00000000000..e20b20051da --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_26.diag.txt @@ -0,0 +1,4 @@ +/kt45461_26.kt:13:44: error: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Out, K, Out + val x: Out = Bar>().takeFoo(foo) + ^ + diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_26.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_26.fir.kt new file mode 100644 index 00000000000..cb7348b5480 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_26.fir.kt @@ -0,0 +1,14 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection +class Foo + +class Bar { + fun takeFoo(foo: Foo): S = null as S +} + +class Out + +fun Out> main() { + val foo = Foo() + val x: Out = Bar>()., K")!>takeFoo(foo) +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_26.kt b/compiler/testData/diagnostics/tests/inference/kt45461_26.kt new file mode 100644 index 00000000000..597645a5ab5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_26.kt @@ -0,0 +1,14 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection +class Foo + +class Bar { + fun takeFoo(foo: Foo): S = null as S +} + +class Out + +fun Out> main() { + val foo = Foo() + val x: Out = Bar>()., K, Out")!>takeFoo(foo) +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_26.txt b/compiler/testData/diagnostics/tests/inference/kt45461_26.txt new file mode 100644 index 00000000000..02d9d21cf0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_26.txt @@ -0,0 +1,25 @@ +package + +public fun > main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): S + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Out { + public constructor Out() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_27.kt b/compiler/testData/diagnostics/tests/inference/kt45461_27.kt new file mode 100644 index 00000000000..460586c9478 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_27.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_27.txt b/compiler/testData/diagnostics/tests/inference/kt45461_27.txt new file mode 100644 index 00000000000..85ca69788d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_27.txt @@ -0,0 +1,25 @@ +package + +public fun >> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_28.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_28.fir.kt new file mode 100644 index 00000000000..82632a9383a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_28.fir.kt @@ -0,0 +1,12 @@ +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_28.kt b/compiler/testData/diagnostics/tests/inference/kt45461_28.kt new file mode 100644 index 00000000000..91ec17ab6d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_28.kt @@ -0,0 +1,12 @@ +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv + +fun >> main() { + val foo = Foo() + Bar>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_28.txt b/compiler/testData/diagnostics/tests/inference/kt45461_28.txt new file mode 100644 index 00000000000..85ca69788d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_28.txt @@ -0,0 +1,25 @@ +package + +public fun >> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_5.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_5.diag.txt index 345c7877044..56d82edb652 100644 --- a/compiler/testData/diagnostics/tests/inference/kt45461_5.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/kt45461_5.diag.txt @@ -1,9 +1,6 @@ /kt45461_5.kt:5:25: warning: parameter 'foo' is never used fun takeFoo(foo: Foo) {} ^ -/kt45461_5.kt:8:23: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined -fun main() { - ^ -/kt45461_5.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.8 +/kt45461_5.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.9 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_5.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_5.fir.kt index 350fcda5b69..b48314f6e46 100644 --- a/compiler/testData/diagnostics/tests/inference/kt45461_5.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/kt45461_5.fir.kt @@ -5,7 +5,7 @@ class Bar { fun takeFoo(foo: Foo) {} } -fun Int> main() { +fun main() { val foo = Foo() Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_5.kt b/compiler/testData/diagnostics/tests/inference/kt45461_5.kt index bdd866063bf..cc208e86568 100644 --- a/compiler/testData/diagnostics/tests/inference/kt45461_5.kt +++ b/compiler/testData/diagnostics/tests/inference/kt45461_5.kt @@ -5,7 +5,7 @@ class Bar { fun takeFoo(foo: Foo) {} } -fun Int> main() { +fun main() { val foo = Foo() Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 } diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_5.txt b/compiler/testData/diagnostics/tests/inference/kt45461_5.txt index 17f69029a04..c5e8b48dde8 100644 --- a/compiler/testData/diagnostics/tests/inference/kt45461_5.txt +++ b/compiler/testData/diagnostics/tests/inference/kt45461_5.txt @@ -1,6 +1,6 @@ package -public fun main(): kotlin.Unit +public fun main(): kotlin.Unit public final class Bar { public constructor Bar() diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_6.kt b/compiler/testData/diagnostics/tests/inference/kt45461_6.kt new file mode 100644 index 00000000000..104d08748d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_6.kt @@ -0,0 +1,11 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +fun main() { + val foo = Foo() + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_6.txt b/compiler/testData/diagnostics/tests/inference/kt45461_6.txt new file mode 100644 index 00000000000..c5e8b48dde8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_6.txt @@ -0,0 +1,18 @@ +package + +public fun main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_7.kt b/compiler/testData/diagnostics/tests/inference/kt45461_7.kt new file mode 100644 index 00000000000..9a66f2da610 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_7.kt @@ -0,0 +1,11 @@ +// FIR_IDENTICAL +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +fun Int> main() { + val foo = Foo() + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_7.txt b/compiler/testData/diagnostics/tests/inference/kt45461_7.txt new file mode 100644 index 00000000000..17f69029a04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_7.txt @@ -0,0 +1,18 @@ +package + +public fun main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_8.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_8.diag.txt new file mode 100644 index 00000000000..4bd649a4ead --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_8.diag.txt @@ -0,0 +1,9 @@ +/kt45461_8.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_8.kt:10:28: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined +fun , L : N, N: Int> main() { + ^ +/kt45461_8.kt:12:24: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv, K. This will become an error in Kotlin 1.9 + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_8.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_8.fir.kt new file mode 100644 index 00000000000..ccba1a5610d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_8.fir.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +fun , L : N, N: Int> main() { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_8.kt b/compiler/testData/diagnostics/tests/inference/kt45461_8.kt new file mode 100644 index 00000000000..81534b2a38a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_8.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +fun , L : N, N: Int> main() { + val foo = Foo() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_8.txt b/compiler/testData/diagnostics/tests/inference/kt45461_8.txt new file mode 100644 index 00000000000..0082783c4c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_8.txt @@ -0,0 +1,25 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : kotlin.Int> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_9.diag.txt b/compiler/testData/diagnostics/tests/inference/kt45461_9.diag.txt new file mode 100644 index 00000000000..18810e64d8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_9.diag.txt @@ -0,0 +1,7 @@ +/kt45461_9.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_9.kt:12:21: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv, Inv. This will become an error in Kotlin 1.9 + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + ^ + diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_9.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461_9.fir.kt new file mode 100644 index 00000000000..cf30ece6fa7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_9.fir.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +fun , L : N, N: Number> main() { + val foo = Foo>() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_9.kt b/compiler/testData/diagnostics/tests/inference/kt45461_9.kt new file mode 100644 index 00000000000..a6d1e9c3e2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_9.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +class Inv

+ +fun , L : N, N: Number> main() { + val foo = Foo>() + Bar>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} diff --git a/compiler/testData/diagnostics/tests/inference/kt45461_9.txt b/compiler/testData/diagnostics/tests/inference/kt45461_9.txt new file mode 100644 index 00000000000..ed1b09b14c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461_9.txt @@ -0,0 +1,25 @@ +package + +public fun , /*1*/ L : N, /*2*/ N : kotlin.Number> main(): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun takeFoo(/*0*/ foo: Foo): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Inv { + public constructor Inv() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/kt48765.diag.txt b/compiler/testData/diagnostics/tests/inference/kt48765.diag.txt index f30446d8d81..9cdd3d42adb 100644 --- a/compiler/testData/diagnostics/tests/inference/kt48765.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/kt48765.diag.txt @@ -4,7 +4,7 @@ /kt48765.kt:4:52: warning: parameter 'x2' is never used fun > foo(x1: T2, x2: T1) {} ^ -/kt48765.kt:8:13: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: String, Number. This will become an error in Kotlin 1.8 +/kt48765.kt:8:13: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: String, Number. This will become an error in Kotlin 1.9 B().foo(x, foo()) ^ /kt48765.kt:12:9: warning: 'String' is a final type, and thus a value of the type parameter is predetermined diff --git a/compiler/testData/diagnostics/tests/inference/kt48935.diag.txt b/compiler/testData/diagnostics/tests/inference/kt48935.diag.txt index 8cb6db989a0..f1aa80bfbf2 100644 --- a/compiler/testData/diagnostics/tests/inference/kt48935.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/kt48935.diag.txt @@ -1,7 +1,4 @@ -/kt48935.kt:6:35: warning: parameter 'func' is never used +/kt48935.kt:7:35: warning: parameter 'func' is never used fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { ^ -/kt48935.kt:12:5: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: Base, DoesNotImplementBase. This will become an error in Kotlin 1.8 - exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied - ^ diff --git a/compiler/testData/diagnostics/tests/inference/kt49661.diag.txt b/compiler/testData/diagnostics/tests/inference/kt49661.diag.txt index 43f7298dc17..05869b84ec2 100644 --- a/compiler/testData/diagnostics/tests/inference/kt49661.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/kt49661.diag.txt @@ -1,4 +1,4 @@ -/kt49661.kt:10:5: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: Foo, Int. This will become an error in Kotlin 1.8 +/kt49661.kt:10:5: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: Foo, Int. This will become an error in Kotlin 1.9 f { g() } ^ diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.fir.kt new file mode 100644 index 00000000000..769d87137c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.fir.kt @@ -0,0 +1,7 @@ +fun String> g(): T? = null + +fun f(block: () -> R?): R? = block() + +fun main() { + f { g() /* OK, g() is inferred into {Int & String}? */ } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt new file mode 100644 index 00000000000..3a9f23bef4a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt @@ -0,0 +1,7 @@ +fun String> g(): T? = null + +fun f(block: () -> R?): R? = block() + +fun main() { + f { g() /* OK, g() is inferred into {Int & String}? */ } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.txt b/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.txt new file mode 100644 index 00000000000..e1a1468ea8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.txt @@ -0,0 +1,5 @@ +package + +public fun f(/*0*/ block: () -> R?): R? +public fun g(): T? +public fun main(): kotlin.Unit 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 558ade22bdd..bded9a046df 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 @@ -13846,12 +13846,126 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt"); } + @Test + @TestMetadata("kt45461_10.kt") + public void testKt45461_10() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_10.kt"); + } + + @Test + @TestMetadata("kt45461_11.kt") + public void testKt45461_11() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_11.kt"); + } + + @Test + @TestMetadata("kt45461_12.kt") + public void testKt45461_12() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_12.kt"); + } + + @Test + @TestMetadata("kt45461_13.kt") + public void testKt45461_13() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_13.kt"); + } + + @Test + @TestMetadata("kt45461_14.kt") + public void testKt45461_14() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_14.kt"); + } + + @Test + @TestMetadata("kt45461_15.kt") + public void testKt45461_15() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_15.kt"); + } + + @Test + @TestMetadata("kt45461_16.kt") + public void testKt45461_16() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_16.kt"); + } + + @Test + @TestMetadata("kt45461_17.kt") + public void testKt45461_17() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_17.kt"); + } + + @Test + @TestMetadata("kt45461_18.kt") + public void testKt45461_18() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_18.kt"); + } + + @Test + @TestMetadata("kt45461_19.kt") + public void testKt45461_19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_19.kt"); + } + @Test @TestMetadata("kt45461_2.kt") public void testKt45461_2() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt"); } + @Test + @TestMetadata("kt45461_20.kt") + public void testKt45461_20() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_20.kt"); + } + + @Test + @TestMetadata("kt45461_21.kt") + public void testKt45461_21() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_21.kt"); + } + + @Test + @TestMetadata("kt45461_22.kt") + public void testKt45461_22() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_22.kt"); + } + + @Test + @TestMetadata("kt45461_23.kt") + public void testKt45461_23() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_23.kt"); + } + + @Test + @TestMetadata("kt45461_24.kt") + public void testKt45461_24() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_24.kt"); + } + + @Test + @TestMetadata("kt45461_25.kt") + public void testKt45461_25() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_25.kt"); + } + + @Test + @TestMetadata("kt45461_26.kt") + public void testKt45461_26() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_26.kt"); + } + + @Test + @TestMetadata("kt45461_27.kt") + public void testKt45461_27() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_27.kt"); + } + + @Test + @TestMetadata("kt45461_28.kt") + public void testKt45461_28() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_28.kt"); + } + @Test @TestMetadata("kt45461_3.kt") public void testKt45461_3() throws Exception { @@ -13870,6 +13984,30 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt"); } + @Test + @TestMetadata("kt45461_6.kt") + public void testKt45461_6() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_6.kt"); + } + + @Test + @TestMetadata("kt45461_7.kt") + public void testKt45461_7() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_7.kt"); + } + + @Test + @TestMetadata("kt45461_8.kt") + public void testKt45461_8() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_8.kt"); + } + + @Test + @TestMetadata("kt45461_9.kt") + public void testKt45461_9() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt45461_9.kt"); + } + @Test @TestMetadata("kt46515.kt") public void testKt46515() throws Exception { @@ -13894,6 +14032,36 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt"); } + @Test + @TestMetadata("kt48935_2.kt") + public void testKt48935_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt"); + } + + @Test + @TestMetadata("kt48935_3.kt") + public void testKt48935_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt"); + } + + @Test + @TestMetadata("kt48935_4.kt") + public void testKt48935_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt"); + } + + @Test + @TestMetadata("kt48935_5.kt") + public void testKt48935_5() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_5.kt"); + } + + @Test + @TestMetadata("kt48935_6.kt") + public void testKt48935_6() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt48935_6.kt"); + } + @Test @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { @@ -16465,6 +16633,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt"); } + @Test + @TestMetadata("nullableEmptyIntersection.kt") + public void testNullableEmptyIntersection() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt"); + } + @Test @TestMetadata("typeParameterAsUpperBound.kt") public void testTypeParameterAsUpperBound() throws Exception { diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt new file mode 100644 index 00000000000..9b86ee1305a --- /dev/null +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.types + +enum class EmptyIntersectionTypeKind { NOT_EMPTY_INTERSECTION, MULTIPLE_CLASSES, SINGLE_FINAL_CLASS } + +fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean = this == EmptyIntersectionTypeKind.MULTIPLE_CLASSES + +fun EmptyIntersectionTypeKind.isPossibleEmpty(): Boolean = this == EmptyIntersectionTypeKind.SINGLE_FINAL_CLASS diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index 956126df3ce..b3b6050fe15 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -5,9 +5,7 @@ package org.jetbrains.kotlin.types.model -import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.jetbrains.kotlin.types.TypeCheckerState -import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.types.* import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -158,7 +156,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui fun TypeConstructorMarker.isCapturedTypeConstructor(): Boolean - fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean + fun KotlinTypeMarker.eraseContainingTypeParameters(): KotlinTypeMarker fun Collection.singleBestRepresentative(): KotlinTypeMarker? @@ -176,8 +174,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui fun createStubTypeForBuilderInference(typeVariable: TypeVariableMarker): StubTypeMarker fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker - fun KotlinTypeMarker.isFinal(): Boolean - fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker @@ -263,7 +259,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker - private fun KotlinTypeMarker.extractTypeVariables(to: MutableSet) { + private fun KotlinTypeMarker.extractTypeOf(to: MutableSet, getIfApplicable: (TypeConstructorMarker) -> T?) { for (i in 0 until argumentsCount()) { val argument = getArgument(i) @@ -271,16 +267,26 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui val argumentType = argument.getType() val argumentTypeConstructor = argumentType.typeConstructor() - if (argumentTypeConstructor is TypeVariableTypeConstructorMarker) { - to.add(argumentTypeConstructor) + val argumentToAdd = getIfApplicable(argumentTypeConstructor) + + if (argumentToAdd != null) { + to.add(argumentToAdd) } else if (argumentType.argumentsCount() != 0) { - argumentType.extractTypeVariables(to) + argumentType.extractTypeOf(to, getIfApplicable) } } } - @OptIn(ExperimentalStdlibApi::class) - fun KotlinTypeMarker.extractTypeVariables() = buildSet { extractTypeVariables(this) } + fun KotlinTypeMarker.extractTypeVariables(): Set = + buildSet { + extractTypeOf(this) { it as? TypeVariableTypeConstructorMarker } + } + + fun KotlinTypeMarker.extractTypeParameters(): Set = + buildSet { + typeConstructor().getTypeParameterClassifier()?.let(::add) + extractTypeOf(this) { it.getTypeParameterClassifier() } + } /** * For case Foo <: (T..T?) return LowerBound for new constraint LowerBound <: T @@ -310,6 +316,172 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui return createCapturedType(starProjection, listOf(superType), lowerType = null, CaptureStatus.FROM_EXPRESSION) } + + fun Collection.computeEmptyIntersectionTypeKind(): EmptyIntersectionTypeKind { + if (this.isEmpty()) + return EmptyIntersectionTypeKind.NOT_EMPTY_INTERSECTION + + val types = this.withIndex() + + for ((i, firstType) in types) { + if (!firstType.typeConstructor().mayCauseEmptyIntersection()) + continue + + val doesFirstTypeContainTypeParameters by lazy { firstType.contains { it.typeConstructor().isTypeParameterTypeConstructor() } } + val firstSubstitutedType by lazy { firstType.eraseContainingTypeParameters() } + + for ((j, secondType) in types) { + if (i >= j || !secondType.typeConstructor().mayCauseEmptyIntersection()) continue + + val doesSecondTypeContainTypeParameters = secondType.contains { it.typeConstructor().isTypeParameterTypeConstructor() } + val secondSubstitutedType by lazy { secondType.eraseContainingTypeParameters() } + val anyContainingTypeParameter = doesFirstTypeContainTypeParameters || doesSecondTypeContainTypeParameters + + when { + !anyContainingTypeParameter && !canHaveSubtype(listOf(firstType, secondType)) -> + return EmptyIntersectionTypeKind.MULTIPLE_CLASSES + anyContainingTypeParameter && !canHaveSubtype(listOf(firstSubstitutedType, secondSubstitutedType)) -> + return EmptyIntersectionTypeKind.MULTIPLE_CLASSES + } + } + } + + return EmptyIntersectionTypeKind.NOT_EMPTY_INTERSECTION + } + + private fun canHaveSubtype(types: List): Boolean { + val expandedTypes = types.map { + if (it.typeConstructor() is IntersectionTypeConstructorMarker) { + it.typeConstructor().supertypes().toList() + } else listOf(it) + }.flatten().withIndex() + + val typeCheckerState = newTypeCheckerState(errorTypesEqualToAnything = true, stubTypesEqualToAnything = true) + + for ((i, firstType) in expandedTypes) { + val firstTypeConstructor = firstType.typeConstructor() + + if (!firstTypeConstructor.mayCauseEmptyIntersection()) + continue + + for ((j, secondType) in expandedTypes) { + if (i >= j) continue + + val secondTypeConstructor = secondType.typeConstructor() + + if (!secondTypeConstructor.mayCauseEmptyIntersection()) + continue + + if (areEqualTypeConstructors(firstTypeConstructor, secondTypeConstructor) && secondTypeConstructor.parametersCount() == 0) + continue + + // Below is determining having subtypes for two classes + // A class type may have only one supertype of class-based type constructor + val superTypeByFirstConstructor = AbstractTypeChecker.findCorrespondingSupertypes( + typeCheckerState, firstType.lowerBoundIfFlexible(), secondTypeConstructor + ).takeIf { it.isNotEmpty() }?.single() + val superTypeBySecondConstructor = AbstractTypeChecker.findCorrespondingSupertypes( + typeCheckerState, secondType.lowerBoundIfFlexible(), firstTypeConstructor + ).takeIf { it.isNotEmpty() }?.single() + + if (superTypeByFirstConstructor == null && superTypeBySecondConstructor == null) + return false + + if (superTypeByFirstConstructor == null || superTypeBySecondConstructor == null) + continue // first or second is actually subtype of another + + if (!areTypeArgumentsCompatibleToHaveSubtypes(superTypeByFirstConstructor, superTypeBySecondConstructor)) { + return false + } + } + } + + return true + } + + private fun TypeArgumentMarker.uncaptureIfNeeded(): TypeArgumentMarker { + val type = getType() + return if (type is CapturedTypeMarker) type.typeConstructorProjection() else this + } + + private fun computeEffectiveVariance(parameter: TypeParameterMarker, argument: TypeArgumentMarker): TypeVariance? = + AbstractTypeChecker.effectiveVariance(parameter.getVariance(), argument.getVariance()) + + private fun TypeConstructorMarker.mayCauseEmptyIntersection(): Boolean = + (isClassTypeConstructor() || isTypeParameterTypeConstructor()) && !isInterface() && !isAnyConstructor() && !isNothingConstructor() + + private fun areArgumentsOfSpecifiedVariances( + firstType: KotlinTypeMarker, + secondType: KotlinTypeMarker, + argumentIndex: Int, + variance1: TypeVariance, + variance2: TypeVariance, + ): Boolean { + val argumentOfFirst = firstType.getArgument(argumentIndex).uncaptureIfNeeded() + val parameterOfFirst = firstType.typeConstructor().getParameter(argumentIndex) + + val argumentOfSecond = secondType.getArgument(argumentIndex).uncaptureIfNeeded() + val parameterOfSecond = secondType.typeConstructor().getParameter(argumentIndex) + + val effectiveVariance1 = AbstractTypeChecker.effectiveVariance(parameterOfFirst.getVariance(), argumentOfFirst.getVariance()) + val effectiveVariance2 = AbstractTypeChecker.effectiveVariance(parameterOfSecond.getVariance(), argumentOfSecond.getVariance()) + + return (effectiveVariance1 == variance1 && effectiveVariance2 == variance2) + || (effectiveVariance1 == variance2 && effectiveVariance2 == variance1) + } + + private fun areTypeArgumentsCompatibleToHaveSubtypes(firstType: KotlinTypeMarker, secondType: KotlinTypeMarker): Boolean { + require(firstType.typeConstructor() == secondType.typeConstructor()) { + "Type constructors of the passed types should be the same to compare their arguments" + } + + fun isSubtypeOf(firstType: KotlinTypeMarker, secondType: KotlinTypeMarker) = + AbstractTypeChecker.isSubtypeOf(this, firstType, secondType) + + for ((i, argumentOfFirst) in firstType.getArguments().withIndex()) { + @Suppress("NAME_SHADOWING") + val argumentOfFirst = argumentOfFirst.uncaptureIfNeeded() + val argumentOfSecond = secondType.getArgument(i).uncaptureIfNeeded() + + if (argumentOfFirst == argumentOfSecond || argumentOfFirst.isStarProjection() || argumentOfSecond.isStarProjection()) + continue + + val argumentTypeOfFirst = argumentOfFirst.getType() + val argumentTypeOfSecond = argumentOfSecond.getType() + + when { + areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.INV, TypeVariance.INV) -> + return false + areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.INV, TypeVariance.OUT) -> { + if (!isSubtypeOf(argumentTypeOfFirst, argumentTypeOfSecond)) { + return false + } + } + areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.INV, TypeVariance.IN) -> { + if (!isSubtypeOf(argumentTypeOfSecond, argumentTypeOfFirst)) { + return false + } + } + areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.IN, TypeVariance.OUT) -> { + if (argumentTypeOfFirst.argumentsCount() == 0 && argumentTypeOfSecond.argumentsCount() == 0) { + if (!isSubtypeOf(argumentTypeOfFirst, argumentTypeOfSecond)) { + return false + } + } else if (!canHaveSubtype(listOf(argumentTypeOfFirst, argumentTypeOfSecond))) { + return false + } + } + areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.OUT, TypeVariance.OUT) + || areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.IN, TypeVariance.IN) -> { + if (!canHaveSubtype(listOf(argumentTypeOfFirst, argumentTypeOfSecond))) { + return false + } + } + } + } + + return true + } } @@ -389,6 +561,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext { fun TypeConstructorMarker.isLocalType(): Boolean fun TypeConstructorMarker.isAnonymous(): Boolean fun TypeConstructorMarker.getTypeParameterClassifier(): TypeParameterMarker? + fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean val TypeVariableTypeConstructorMarker.typeParameter: TypeParameterMarker? diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 865d1d0e83f..e9950501ed7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -460,11 +460,6 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy return makeSimpleTypeDefinitelyNotNullOrNotNullInternal(this) } - override fun KotlinTypeMarker.isFinal(): Boolean { - require(this is KotlinType, this::errorMessage) - return !TypeUtils.canHaveSubtypes(KotlinTypeChecker.DEFAULT, this) - } - override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker { require(this is UnwrappedType, this::errorMessage) return this.replaceAnnotations(Annotations.EMPTY) @@ -714,6 +709,17 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy return this is NewCapturedTypeConstructor } + override fun KotlinTypeMarker.eraseContainingTypeParameters(): KotlinTypeMarker { + val eraser = TypeParameterUpperBoundEraser( + ErasureProjectionComputer(), + TypeParameterErasureOptions(leaveNonTypeParameterTypes = true, intersectUpperBounds = true) + ) + val typeParameters = this.extractTypeParameters() + .map { it as TypeParameterDescriptor } + .associateWith { TypeProjectionImpl(eraser.getErasedUpperBound(it, ErasureTypeAttributes(TypeUsage.COMMON))) } + return TypeConstructorSubstitution.createByParametersMap(typeParameters).buildSubstitutor().safeSubstitute(this) + } + override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean { return this is ClassifierBasedTypeConstructor && this.declarationDescriptor is AbstractTypeParameterDescriptor }