K2: Fix processing inference lower bound NullableType <: T & Any

This commit is a follow-up to 0d070f8ba9.
Here we remove accidentally returning "Not a sub-type" for a constraint
like TypeVariable <: DNN type

#KT-59241 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-06-12 15:01:30 +02:00
committed by Space Team
parent ab1d634ad3
commit 35b475f9f7
3 changed files with 6 additions and 26 deletions
@@ -218,12 +218,15 @@ abstract class TypeCheckerStateForConstraintSystem(
subType: KotlinTypeMarker,
isFromNullabilityConstraint: Boolean = false
): Boolean = with(extensionTypeContext) {
val subTypeConstructor = subType.typeConstructor()
val lowerConstraint = when (typeVariable) {
is SimpleTypeMarker ->
when {
// Foo? (any type which cannot be used as dispatch receiver because of nullability) <: T & Any => ERROR (for K2 only)
isK2 && typeVariable.isDefinitelyNotNullType()
&& !AbstractNullabilityChecker.isSubtypeOfAny(extensionTypeContext, subType) -> return false
isK2 && typeVariable.isDefinitelyNotNullType() && !subTypeConstructor.isTypeVariable() &&
!AbstractNullabilityChecker.isSubtypeOfAny(extensionTypeContext, subType) -> {
return false
}
/*
* Foo <: T? (T is contained in invariant or contravariant positions of a return type) -- Foo <: T
* Example:
@@ -236,7 +239,6 @@ abstract class TypeCheckerStateForConstraintSystem(
*/
typeVariable.isMarkedNullable() -> {
val typeVariableTypeConstructor = typeVariable.typeConstructor()
val subTypeConstructor = subType.typeConstructor()
val needToMakeDefNotNull = subTypeConstructor.isTypeVariable() ||
typeVariableTypeConstructor !is TypeVariableTypeConstructorMarker ||
!typeVariableTypeConstructor.isContainedInInvariantOrContravariantPositions()
@@ -1,23 +0,0 @@
// FULL_JDK
// FILE: JavaClass.java
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
public class JavaClass {
public static <E> void consume(@NotNull E value) {}
public static <E> void compute(Supplier<@NotNull E> computable) {}
}
// FILE: KotlinMain.kt
fun test1() {
JavaClass.compute { <!ARGUMENT_TYPE_MISMATCH!>42.apply {}<!> }
}
fun test2() {
JavaClass.compute { <!ARGUMENT_TYPE_MISMATCH!>if (true) 42 else 42<!> }
}
fun test3() {
42.<!INAPPLICABLE_CANDIDATE!>apply<!>(JavaClass::<!UNRESOLVED_REFERENCE!>consume<!>)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FULL_JDK
// FILE: JavaClass.java