diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index e6b915d7ffd..3df7305f368 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -15065,6 +15065,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt"); } + @TestMetadata("genericSamSmartcast.kt") + public void testGenericSamSmartcast() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt"); + } + @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt"); diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index ed3ab742278..88370a15cc6 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -613,12 +613,13 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca for (i in underlyingValueParameters.indices) { val underlyingValueParameter = underlyingValueParameters[i] - val expectedSamConversionTypesForVararg = ArrayList() - if (expectSamConvertedArgumentToBeAvailableInResolvedCall && resolvedCall is NewResolvedCallImpl<*>) { - val arguments = resolvedCall.valueArguments[originalValueParameters[i]]?.arguments ?: continue - arguments.mapTo(expectedSamConversionTypesForVararg) { resolvedCall.getExpectedTypeForSamConvertedArgument(it) } - if (expectedSamConversionTypesForVararg.all { it == null }) continue - } else { + val expectedSamConversionTypesForVararg = + if (expectSamConvertedArgumentToBeAvailableInResolvedCall && resolvedCall is NewResolvedCallImpl<*>) { + val arguments = resolvedCall.valueArguments[originalValueParameters[i]]?.arguments + arguments?.map { resolvedCall.getExpectedTypeForSamConvertedArgument(it) } + } else null + + if (expectedSamConversionTypesForVararg?.all { it == null } != false) { // When the method is `f(T)` with `T` = a SAM type, the substituted type is a SAM while the original is not; // when the method is `f(X)` with `T` = `out V` where `X` is a SAM type, the substituted type is `Nothing` // while the original is a SAM interface. Thus, if *either* of those is a SAM type then it's fine. @@ -675,8 +676,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca ).apply { originalArgument.elements.mapIndexedTo(elements) { index, element -> if (element is IrExpression) { - val samType = expectedSamConversionTypesForVararg[index] - if (samType != null) + if (expectedSamConversionTypesForVararg?.get(index) != null) samConvertScalarExpression(element) else element diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt index 1501ab6c8a1..c5e686b1dd5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.ir.util -import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclaration @@ -32,11 +31,6 @@ class ExternalDependenciesGenerator( private val languageVersionSettings: LanguageVersionSettings ) { fun generateUnboundSymbolsAsDependencies() { - if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) { - require(symbolTable.unboundTypeParameters.isEmpty()) { - "Unbound type parameters are forbidden: ${symbolTable.unboundTypeParameters}" - } - } // There should be at most one DeclarationStubGenerator (none in closed world?) irProviders.singleOrNull { it is DeclarationStubGenerator }?.let { (it as DeclarationStubGenerator).unboundSymbolGeneration = true diff --git a/compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt b/compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt index bb275c2a0b7..5584c00ffc0 100644 --- a/compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt +++ b/compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt @@ -1,6 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND: JVM_IR - // FILE: example/Hello.java package example; diff --git a/compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt b/compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt new file mode 100644 index 00000000000..6ab26cd7987 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt @@ -0,0 +1,21 @@ +// TARGET_BACKEND: JVM +// FILE: A.java +public class A { + public interface I { + String apply(T x); + } + + public String call(I block) { return block.apply(null); } +} + +// FILE: test.kt +fun f(x: Any): String { + if (x is A<*>) { + return x.call { y: Any? -> "OK" } + } + return "Fail" +} + +fun box(): String { + return f(A()) +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 0abc6039c43..056acf2dd5b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16290,6 +16290,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt"); } + @TestMetadata("genericSamSmartcast.kt") + public void testGenericSamSmartcast() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt"); + } + @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 5e134ce11e1..2cb8efe94e9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16290,6 +16290,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt"); } + @TestMetadata("genericSamSmartcast.kt") + public void testGenericSamSmartcast() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt"); + } + @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index bb438f0b592..9d2f3b15aed 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -15065,6 +15065,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt"); } + @TestMetadata("genericSamSmartcast.kt") + public void testGenericSamSmartcast() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/genericSamSmartcast.kt"); + } + @TestMetadata("lambdaInstanceOf.kt") public void testLambdaInstanceOf() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");