[NI] Fix extracting type variables for flexible types in in captured types

Bug was introduced in b99efb because of lack of tests.
All code in `AbstractTypeCheckerContextForConstraintSystem.extractTypeVariableForSubtype`
  related to IN projection looks suspicious and needs further investigation
This commit is contained in:
Dmitriy Novozhilov
2019-08-01 10:54:11 +03:00
parent 71a1a0e2f5
commit b6a7d21579
6 changed files with 44 additions and 1 deletions
@@ -9541,6 +9541,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt");
}
@TestMetadata("capturedInProjectedFlexibleType.kt")
public void testCapturedInProjectedFlexibleType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.kt");
}
@TestMetadata("coerceFunctionLiteralToSuspend.kt")
public void testCoerceFunctionLiteralToSuspend() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.kt");
@@ -90,7 +90,7 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
val projection = typeMarker.typeConstructorProjection()
if (projection.isStarProjection()) return null
if (projection.getVariance() == TypeVariance.IN) {
val type = projection.getType().let { it.asSimpleType() ?: it.asFlexibleType()?.lowerBound() } ?: return null
val type = projection.getType().asSimpleType() ?: return null
if (isMyTypeVariable(type)) {
simplifyLowerConstraint(type, superType)
if (isMyTypeVariable(superType.asSimpleType() ?: return null)) {
@@ -0,0 +1,16 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: A.java
public class A<T> {
public A<? super T> getSuperA() { return null; }
}
// FILE: main.kt
fun <T : Any> foo(x: T?, func: (T) -> T?) {}
fun test(a: A<*>) {
foo(a) { it.superA }
}
@@ -0,0 +1,12 @@
package
public fun </*0*/ T : kotlin.Any> foo(/*0*/ x: T?, /*1*/ func: (T) -> T?): kotlin.Unit
public fun test(/*0*/ a: A<*>): kotlin.Unit
public open class A</*0*/ T : kotlin.Any!> {
public constructor A</*0*/ T : kotlin.Any!>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun getSuperA(): A<in T!>!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -9548,6 +9548,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt");
}
@TestMetadata("capturedInProjectedFlexibleType.kt")
public void testCapturedInProjectedFlexibleType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.kt");
}
@TestMetadata("coerceFunctionLiteralToSuspend.kt")
public void testCoerceFunctionLiteralToSuspend() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.kt");
@@ -9543,6 +9543,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt");
}
@TestMetadata("capturedInProjectedFlexibleType.kt")
public void testCapturedInProjectedFlexibleType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.kt");
}
@TestMetadata("coerceFunctionLiteralToSuspend.kt")
public void testCoerceFunctionLiteralToSuspend() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.kt");