[NI] Fix exception on capturing stub type from coroutine-inference

#KT-30853 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-05-06 18:03:20 +03:00
parent 90f11211d3
commit 1fecd15355
5 changed files with 54 additions and 0 deletions
@@ -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'," +
@@ -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 <K> iFlow(@BuilderInference block: suspend iFlowCollector<in K>.() -> Unit): iFlow<K> = TODO()
interface iFlowCollector<S> {
suspend fun emit(value: S)
}
interface iFlow<out V>
@@ -0,0 +1,17 @@
package
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ K> iFlow(/*0*/ @kotlin.BuilderInference block: suspend iFlowCollector<in K>.() -> kotlin.Unit): iFlow<K>
public suspend fun main(): kotlin.Unit
public interface iFlow</*0*/ out V> {
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</*0*/ S> {
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
}
@@ -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");
@@ -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");