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 7cbe7640626..8bf236d45ad 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 @@ -22200,6 +22200,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/j+k/rawOverride.kt"); } + @Test + @TestMetadata("rawTypeCrash.kt") + public void testRawTypeCrash() { + runTest("compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt"); + } + @Test @TestMetadata("rawTypeScope.kt") public void testRawTypeScope() { 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 219e27269a4..d67338c3110 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 @@ -22200,6 +22200,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/j+k/rawOverride.kt"); } + @Test + @TestMetadata("rawTypeCrash.kt") + public void testRawTypeCrash() { + runTest("compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt"); + } + @Test @TestMetadata("rawTypeScope.kt") public void testRawTypeScope() { 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 fe320f6bb9b..c3fe05bf190 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 @@ -22194,6 +22194,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/j+k/rawOverride.kt"); } + @Test + @TestMetadata("rawTypeCrash.kt") + public void testRawTypeCrash() { + runTest("compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt"); + } + @Test @TestMetadata("rawTypeScope.kt") public void testRawTypeScope() { 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 1478765c1c1..5ebeadaa289 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 @@ -22200,6 +22200,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/j+k/rawOverride.kt"); } + @Test + @TestMetadata("rawTypeCrash.kt") + public void testRawTypeCrash() { + runTest("compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt"); + } + @Test @TestMetadata("rawTypeScope.kt") public void testRawTypeScope() { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt index fd15cce144d..9fabf627ea4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt @@ -141,8 +141,25 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { containingDeclarationSymbol !is FirSyntheticFunctionSymbol && typeParameter.shouldBeFlexible(session.typeContext) ) { - val notNullType = type.withNullability(ConeNullability.NOT_NULL, session.typeContext) as ConeSimpleKotlinType - ConeFlexibleType(notNullType, notNullType.withNullability(ConeNullability.NULLABLE, session.typeContext)) + when (type) { + is ConeSimpleKotlinType -> ConeFlexibleType( + type.withNullability(ConeNullability.NOT_NULL, session.typeContext), + type.withNullability(ConeNullability.NULLABLE, session.typeContext) + ) + /* + * ConeFlexibleTypes have to be handled here + * at least because MapTypeArguments special-cases ConeRawTypes without explicit arguments (KT-54666) + * which allows them to get past the NoExplicitArguments optimization + * in CreateFreshTypeVariableSubstitutorStage.check + * + * (it might be safe to just return the same flexible type without explicitly enforcing flexibility, + * but better safe than sorry when dealing with raw types) + */ + is ConeFlexibleType -> ConeFlexibleType( + type.lowerBound.withNullability(ConeNullability.NOT_NULL, session.typeContext), + type.upperBound.withNullability(ConeNullability.NULLABLE, session.typeContext) + ) + } } else { type } diff --git a/compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt b/compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt new file mode 100644 index 00000000000..bc3a1bee481 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt @@ -0,0 +1,25 @@ +// FIR_IDENTICAL +// ISSUE: KT-66552 + +// FILE: JsStubElementType.java +public interface JsStubElementType> {} + +// FILE: JsStubElement.java +public interface JsStubElement { + > void findChildStubByType(JsStubElementType childStubType); +} + +// FILE: FromJava.java +public interface FromJava { + JsStubElement RAW_TYPED_STUB = null; +} + +// FILE: Kotlin.kt +interface JsStubElementSubType: JsStubElement + +fun test(childStubType: JsStubElementType>) { + val rawTypedStub = FromJava.RAW_TYPED_STUB + if (rawTypedStub is JsStubElementSubType) { + rawTypedStub.findChildStubByType(childStubType) + } +} \ No newline at end of file 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 671159c0002..1b6cb00d1bf 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 @@ -22200,6 +22200,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/j+k/rawOverride.kt"); } + @Test + @TestMetadata("rawTypeCrash.kt") + public void testRawTypeCrash() { + runTest("compiler/testData/diagnostics/tests/j+k/rawTypeCrash.kt"); + } + @Test @TestMetadata("rawTypeScope.kt") public void testRawTypeScope() {