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 094ad8c5657..7a43bb027df 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 @@ -783,6 +783,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/QualifiedExpressions.kt"); } + @Test + @TestMetadata("rawCastToStarProjection_Fail.kt") + public void testRawCastToStarProjection_Fail() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt"); + } + + @Test + @TestMetadata("rawCastToStarProjection_Ok.kt") + public void testRawCastToStarProjection_Ok() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt"); + } + @Test @TestMetadata("RecursiveResolve.kt") public void testRecursiveResolve() 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 0556f6da8c4..da2b675c22a 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 @@ -783,6 +783,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/QualifiedExpressions.kt"); } + @Test + @TestMetadata("rawCastToStarProjection_Fail.kt") + public void testRawCastToStarProjection_Fail() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt"); + } + + @Test + @TestMetadata("rawCastToStarProjection_Ok.kt") + public void testRawCastToStarProjection_Ok() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt"); + } + @Test @TestMetadata("RecursiveResolve.kt") public void testRecursiveResolve() 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 4841a3e5970..a7b136b0dcf 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 @@ -783,6 +783,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/QualifiedExpressions.kt"); } + @Test + @TestMetadata("rawCastToStarProjection_Fail.kt") + public void testRawCastToStarProjection_Fail() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt"); + } + + @Test + @TestMetadata("rawCastToStarProjection_Ok.kt") + public void testRawCastToStarProjection_Ok() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt"); + } + @Test @TestMetadata("RecursiveResolve.kt") public void testRecursiveResolve() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt index 820479de5fc..8b78e813465 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt @@ -78,7 +78,11 @@ fun FirSession.doUnify( } // Foo ~ X? => fail - if (originalType?.nullability != ConeNullability.NULLABLE && typeWithParameters?.nullability == ConeNullability.NULLABLE) { + if ( + originalTypeProjection !is ConeStarProjection && + originalType?.nullability != ConeNullability.NULLABLE && + typeWithParameters?.nullability == ConeNullability.NULLABLE + ) { return true } diff --git a/compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt b/compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt new file mode 100644 index 00000000000..fc921390049 --- /dev/null +++ b/compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt @@ -0,0 +1,9 @@ +// FIR_IDENTICAL +// ISSUE: KT-57095 + +open class ValueType { + class Optional: ValueType() +} +private fun checkType(type: ValueType<*>) { + type as ValueType.Optional // K1: ok, K2: NO_TYPE_ARGUMENTS_ON_RHS +} diff --git a/compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt b/compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt new file mode 100644 index 00000000000..d777101da59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt @@ -0,0 +1,10 @@ +// FIR_IDENTICAL +// ISSUE: KT-57095 + +open class ValueType { + class Optional: ValueType() +} + +private fun checkType(type: ValueType) { + type as ValueType.Optional // K1 & K2: ok +} 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 549c8b2e4e3..b6ab1f455af 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 @@ -783,6 +783,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/QualifiedExpressions.kt"); } + @Test + @TestMetadata("rawCastToStarProjection_Fail.kt") + public void testRawCastToStarProjection_Fail() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Fail.kt"); + } + + @Test + @TestMetadata("rawCastToStarProjection_Ok.kt") + public void testRawCastToStarProjection_Ok() throws Exception { + runTest("compiler/testData/diagnostics/tests/rawCastToStarProjection_Ok.kt"); + } + @Test @TestMetadata("RecursiveResolve.kt") public void testRecursiveResolve() throws Exception {