From 2261928f4f68dec7ead442972277bc1cbf6df142 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 19 Oct 2021 14:21:55 +0300 Subject: [PATCH] Process simple `CapturedType` in `ClassicTypeSystemContext.typeConstructorProjection` as well ^KT-49101 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../tests/inference/capturedTypes/kt49101.kt | 13 ++++++++++ .../tests/inference/capturedTypes/kt49101.txt | 25 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ .../types/checker/ClassicTypeSystemContext.kt | 7 ++++-- 7 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 87cf402ca9d..4e49afac2c4 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 @@ -13812,6 +13812,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.kt"); } + @Test + @TestMetadata("kt49101.kt") + public void testKt49101() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt"); + } + @Test @TestMetadata("memberScopeOfCaptured.kt") public void testMemberScopeOfCaptured() 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 953ca70fe46..7dccaf56f71 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 @@ -13812,6 +13812,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.kt"); } + @Test + @TestMetadata("kt49101.kt") + public void testKt49101() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt"); + } + @Test @TestMetadata("memberScopeOfCaptured.kt") public void testMemberScopeOfCaptured() 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 68832251c05..64e3f59cc50 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 @@ -13812,6 +13812,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.kt"); } + @Test + @TestMetadata("kt49101.kt") + public void testKt49101() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt"); + } + @Test @TestMetadata("memberScopeOfCaptured.kt") public void testMemberScopeOfCaptured() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt new file mode 100644 index 00000000000..65d2aaf3824 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +class A>(val x: T) { + fun test() { + val y: Int = x.m<C>() + } + +} + +class B { + fun > m(): Int = 1 +} + +class C diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.txt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.txt new file mode 100644 index 00000000000..5838794e7e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.txt @@ -0,0 +1,25 @@ +package + +public final class A> { + public constructor A>(/*0*/ x: T) + public final val x: T + 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 test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final 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 final fun > m(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 7611903f7c3..e45842baca8 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 @@ -13818,6 +13818,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.kt"); } + @Test + @TestMetadata("kt49101.kt") + public void testKt49101() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/kt49101.kt"); + } + @Test @TestMetadata("memberScopeOfCaptured.kt") public void testMemberScopeOfCaptured() throws Exception { 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 27ce646e012..c7b272cd142 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -455,8 +455,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy } override fun CapturedTypeMarker.typeConstructorProjection(): TypeArgumentMarker { - require(this is NewCapturedType, this::errorMessage) - return this.constructor.projection + return when (this) { + is NewCapturedType -> this.constructor.projection + is CapturedType -> this.typeProjection + else -> error("Unsupported captured type") + } } override fun CapturedTypeMarker.withNotNullProjection(): KotlinTypeMarker {