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 65abc419ef9..9239640e440 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 @@ -75,6 +75,14 @@ interface NewTypeSubstitutor: TypeSubstitutorMarker { } val capturedType = if (type is DefinitelyNotNullType) type.original as NewCapturedType else type as NewCapturedType val lower = capturedType.lowerType?.let { substitute(it, keepAnnotation, runCapturedChecks = false) } + if (lower != null && capturedType.lowerType is StubType) { + return NewCapturedType( + capturedType.captureStatus, + NewCapturedTypeConstructor(TypeProjectionImpl(typeConstructor.projection.projectionKind, lower)), + lower + ) + } + if (lower != null) throw IllegalStateException( "Illegal type substitutor: $this, " + "because for captured type '$type' lower type approximation should be null, but it is: '$lower'," + diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.kt new file mode 100644 index 00000000000..9877057468f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.Experimental + +import kotlin.experimental.ExperimentalTypeInference + +suspend fun main() { + iFlow { emit(1) } +} + + +@UseExperimental(ExperimentalTypeInference::class) +fun iFlow(@BuilderInference block: suspend iFlowCollector.() -> Unit): iFlow = TODO() + +interface iFlowCollector { + suspend fun emit(value: S) +} + +interface iFlow \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.txt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.txt new file mode 100644 index 00000000000..2b136bdb067 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.txt @@ -0,0 +1,17 @@ +package + +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun iFlow(/*0*/ @kotlin.BuilderInference block: suspend iFlowCollector.() -> kotlin.Unit): iFlow +public suspend fun main(): kotlin.Unit + +public interface iFlow { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface iFlowCollector { + public abstract suspend fun emit(/*0*/ value: S): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index e6aded8cd29..146a6a8e0fe 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1822,6 +1822,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt"); } + @TestMetadata("coroutineInferenceWithCapturedTypeVariable.kt") + public void testCoroutineInferenceWithCapturedTypeVariable() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.kt"); + } + @TestMetadata("correctMember.kt") public void testCorrectMember() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 327953109e5..d8b2272a3c4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -1822,6 +1822,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt"); } + @TestMetadata("coroutineInferenceWithCapturedTypeVariable.kt") + public void testCoroutineInferenceWithCapturedTypeVariable() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.kt"); + } + @TestMetadata("correctMember.kt") public void testCorrectMember() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt");