diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index fb82ea078a0..f20c15c0198 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -23558,6 +23558,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/javaInterop/kt43217.kt"); } + @Test + @TestMetadata("kt48590.kt") + public void testKt48590() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt"); + } + @Test @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index 284c262567c..22a1f497065 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -307,13 +307,18 @@ class ConstraintInjector( override fun addEqualityConstraint(typeVariable: TypeConstructorMarker, type: KotlinTypeMarker) = addConstraint(typeVariable, type, EQUALITY, false) - private fun isCapturedTypeFromSubtyping(type: KotlinTypeMarker) = - when ((type as? CapturedTypeMarker)?.captureStatus()) { - null, CaptureStatus.FROM_EXPRESSION -> false + private fun isCapturedTypeFromSubtyping(type: KotlinTypeMarker): Boolean { + val capturedType = type as? CapturedTypeMarker ?: return false + + if (capturedType.isOldCapturedType()) return false + + return when (capturedType.captureStatus()) { + CaptureStatus.FROM_EXPRESSION -> false CaptureStatus.FOR_SUBTYPING -> true CaptureStatus.FOR_INCORPORATION -> error("Captured type for incorporation shouldn't escape from incorporation: $type\n" + renderBaseConstraint()) } + } private fun addConstraint( typeVariableConstructor: TypeConstructorMarker, diff --git a/compiler/testData/codegen/box/javaInterop/kt48590.kt b/compiler/testData/codegen/box/javaInterop/kt48590.kt new file mode 100644 index 00000000000..a0e3282b73b --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/kt48590.kt @@ -0,0 +1,21 @@ +// WITH_RUNTIME +// TARGET_BACKEND: JVM + +// FILE: Foo.java +public interface Foo { + String into(Class type); + > String into(H handler); +} + +// FILE: Bar.java +public class Bar {} + +// FILE: main.kt +inline fun Foo<*>.into(): String = into(E::class.java) + +fun box(): String { + return (object : Foo { + override fun into(type: Class?): String = "OK" + override fun ?> into(handler: H): String = "NOK" + }).into() +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 3e3b46fd2a1..10619e5487c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -23420,6 +23420,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/kt43217.kt"); } + @Test + @TestMetadata("kt48590.kt") + public void testKt48590() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt"); + } + @Test @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 2cecb82b66c..0647aa1f5d0 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -23558,6 +23558,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/kt43217.kt"); } + @Test + @TestMetadata("kt48590.kt") + public void testKt48590() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt"); + } + @Test @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 35675151d90..4b76facebdb 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19655,6 +19655,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/kt43217.kt"); } + @TestMetadata("kt48590.kt") + public void testKt48590() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt"); + } + @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");