From cb3d65f669054fbe902e54d7e949a88c1901db3f Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 1 Dec 2023 18:17:57 +0100 Subject: [PATCH] [Test] Add test for KT-63996 False-positive TYPE_MISMATCH in builder inference with captured types --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++++ .../stubTypes/capturedTypesId.fir.kt | 36 +++++++++++++++++++ .../stubTypes/capturedTypesId.kt | 36 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++ 7 files changed, 102 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 38cd0de3a14..082846cd748 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -17004,6 +17004,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt"); } + @Test + @TestMetadata("capturedTypesId.kt") + public void testCapturedTypesId() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt"); + } + @Test @TestMetadata("commonSuperType.kt") public void testCommonSuperType() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index a9851d3049d..f71a88f4a7f 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -17004,6 +17004,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt"); } + @Test + @TestMetadata("capturedTypesId.kt") + public void testCapturedTypesId() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt"); + } + @Test @TestMetadata("commonSuperType.kt") public void testCommonSuperType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 349415a8d11..602a71eb843 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -16998,6 +16998,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt"); } + @Test + @TestMetadata("capturedTypesId.kt") + public void testCapturedTypesId() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt"); + } + @Test @TestMetadata("commonSuperType.kt") public void testCommonSuperType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 8733a20c738..4dce4f36449 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -17004,6 +17004,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt"); } + @Test + @TestMetadata("capturedTypesId.kt") + public void testCapturedTypesId() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt"); + } + @Test @TestMetadata("commonSuperType.kt") public void testCommonSuperType() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt new file mode 100644 index 00000000000..5d3650f590b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +UnrestrictedBuilderInference +// !DIAGNOSTICS: -DEPRECATION -UNCHECKED_CAST -OPT_IN_IS_NOT_ENABLED +// WITH_STDLIB +// ISSUE: KT-63996 + +// FILE: main.kt + +fun build(block: TestInterface.() -> Unit): R = TODO() + +interface TestInterface { + fun emit(r: R) + fun getOut(): Inv +} + +class Inv { +} + +fun capture(x: Inv): K = null as K +fun id(x: I): I = null as I + +fun main() { + build { + emit("") + // K is fixed into CapturedType(out NotFixed: TypeVariable(R) + capture(id(getOut())) // unexpected TYPE_MISMATCH (KT-63996) + // capture(getOut()) // OK!!! + Unit + } + build { + emit("") + // K is fixed into CapturedType(out NotFixed: TypeVariable(R) + capture(id(getOut())) // OK!!! + // capture(getOut()) // OK!!! + Unit + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt new file mode 100644 index 00000000000..f0a87063943 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +UnrestrictedBuilderInference +// !DIAGNOSTICS: -DEPRECATION -UNCHECKED_CAST -OPT_IN_IS_NOT_ENABLED +// WITH_STDLIB +// ISSUE: KT-63996 + +// FILE: main.kt + +fun build(block: TestInterface.() -> Unit): R = TODO() + +interface TestInterface { + fun emit(r: R) + fun getOut(): Inv +} + +class Inv { +} + +fun capture(x: Inv): K = null as K +fun id(x: I): I = null as I + +fun main() { + build { + emit("") + // K is fixed into CapturedType(out NotFixed: TypeVariable(R) + capture(id(getOut())) // unexpected TYPE_MISMATCH (KT-63996) + // capture(getOut()) // OK!!! + Unit + } + build { + emit("") + // K is fixed into CapturedType(out NotFixed: TypeVariable(R) + capture(id(getOut())) // OK!!! + // capture(getOut()) // OK!!! + 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 63a938ab75f..1d92411c752 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 @@ -17004,6 +17004,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt"); } + @Test + @TestMetadata("capturedTypesId.kt") + public void testCapturedTypesId() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypesId.kt"); + } + @Test @TestMetadata("commonSuperType.kt") public void testCommonSuperType() throws Exception {