diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt index bc123cb984b..364008d5e2b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt @@ -237,4 +237,6 @@ class ComposedSubstitutor(val left: NewTypeSubstitutor, val right: NewTypeSubsti right.substituteNotNullTypeWithConstructor(constructor)?.constructor ?: constructor ) } + + override val isEmpty: Boolean get() = left.isEmpty && right.isEmpty } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 648ab4b724b..7d10dfd76f2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -264,15 +264,25 @@ class ResolvedAtomCompleter( return } val resultTypeParameters = - callableCandidate.freshSubstitutor!!.freshVariables.map { resultSubstitutor.safeSubstitute(it.defaultType) } + callableCandidate.freshSubstitutor!!.freshVariables.map { resultSubstitutor.safeSubstitute(it.defaultType).asTypeProjection() } + val firstSubstitutor = IndexedParametersSubstitution(callableCandidate.candidate.typeParameters, resultTypeParameters) + val secondSubstitution = object : TypeSubstitution() { + override fun get(key: KotlinType): TypeProjection? { + return resultSubstitutor.safeSubstitute(key.unwrap()).takeIf { it !== key }?.asTypeProjection() + } + + override fun isEmpty(): Boolean { + return resultSubstitutor.isEmpty + } + } + val resultSubstitutor = TypeSubstitutor.createChainedSubstitutor( + firstSubstitutor, + secondSubstitution + ) val psiCallArgument = resolvedAtom.atom.psiCallArgument as CallableReferenceKotlinCallArgumentImpl val callableReferenceExpression = psiCallArgument.ktCallableReferenceExpression - val resultSubstitutor = IndexedParametersSubstitution( - callableCandidate.candidate.typeParameters, - resultTypeParameters.map { it.asTypeProjection() }).buildSubstitutor() - // write down type for callable reference expression val resultType = resultSubstitutor.safeSubstitute(callableCandidate.reflectionCandidateType, Variance.INVARIANT) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt index a58f2db1441..fba419b71a9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt @@ -21,6 +21,8 @@ interface NewTypeSubstitutor: TypeSubstitutorMarker { fun safeSubstitute(type: UnwrappedType): UnwrappedType = substitute(type, runCapturedChecks = true, keepAnnotation = true) ?: type + val isEmpty: Boolean + private fun substitute(type: UnwrappedType, keepAnnotation: Boolean, runCapturedChecks: Boolean): UnwrappedType? = when (type) { is SimpleType -> substitute(type, keepAnnotation, runCapturedChecks) @@ -170,10 +172,14 @@ interface NewTypeSubstitutor: TypeSubstitutorMarker { object EmptySubstitutor : NewTypeSubstitutor { override fun substituteNotNullTypeWithConstructor(constructor: TypeConstructor): UnwrappedType? = null + + override val isEmpty: Boolean get() = true } class NewTypeSubstitutorByConstructorMap(val map: Map) : NewTypeSubstitutor { override fun substituteNotNullTypeWithConstructor(constructor: TypeConstructor): UnwrappedType? = map[constructor] + + override val isEmpty: Boolean get() = map.isEmpty() } class FreshVariableNewTypeSubstitutor(val freshVariables: List) : NewTypeSubstitutor { @@ -185,6 +191,8 @@ class FreshVariableNewTypeSubstitutor(val freshVariables: List { + suspend fun collect(collector: FlowCollector) +} + +interface FlowCollector { + suspend fun emit(value: T) +} + +inline fun Flow.collect(crossinline action: suspend (value: T) -> Unit): Unit {} + +abstract class LiveData + +interface LiveDataScope { + suspend fun emit(value: T) +} + +@UseExperimental(ExperimentalTypeInference::class) +fun liveData(@BuilderInference block: suspend LiveDataScope.() -> Unit): LiveData = null!! + +fun Flow.asLiveData() = liveData { + collect(this::emit) +// collect { emit(it) } +} + +fun box(): String = "OK" \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 3b87cac7ea6..60b59180a89 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12518,6 +12518,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("builderInference.kt") + public void testBuilderInference() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference.kt"); + } + @TestMetadata("capturedStarProjection.kt") public void testCapturedStarProjection() throws Exception { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1dc87b41523..1d162b3c6bc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12518,6 +12518,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("builderInference.kt") + public void testBuilderInference() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference.kt"); + } + @TestMetadata("capturedStarProjection.kt") public void testCapturedStarProjection() throws Exception { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 1a11f9efbd3..2851b11a1b8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -11368,6 +11368,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("builderInference.kt") + public void testBuilderInference() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference.kt"); + } + @TestMetadata("capturedStarProjection.kt") public void testCapturedStarProjection() throws Exception { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index dc96509c4ee..071b7402ee0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11368,6 +11368,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("builderInference.kt") + public void testBuilderInference() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference.kt"); + } + @TestMetadata("capturedStarProjection.kt") public void testCapturedStarProjection() throws Exception { runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt");