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:
committed by
Space Team
parent
ab1d634ad3
commit
35b475f9f7
+5
-3
@@ -218,12 +218,15 @@ abstract class TypeCheckerStateForConstraintSystem(
|
|||||||
subType: KotlinTypeMarker,
|
subType: KotlinTypeMarker,
|
||||||
isFromNullabilityConstraint: Boolean = false
|
isFromNullabilityConstraint: Boolean = false
|
||||||
): Boolean = with(extensionTypeContext) {
|
): Boolean = with(extensionTypeContext) {
|
||||||
|
val subTypeConstructor = subType.typeConstructor()
|
||||||
val lowerConstraint = when (typeVariable) {
|
val lowerConstraint = when (typeVariable) {
|
||||||
is SimpleTypeMarker ->
|
is SimpleTypeMarker ->
|
||||||
when {
|
when {
|
||||||
// Foo? (any type which cannot be used as dispatch receiver because of nullability) <: T & Any => ERROR (for K2 only)
|
// Foo? (any type which cannot be used as dispatch receiver because of nullability) <: T & Any => ERROR (for K2 only)
|
||||||
isK2 && typeVariable.isDefinitelyNotNullType()
|
isK2 && typeVariable.isDefinitelyNotNullType() && !subTypeConstructor.isTypeVariable() &&
|
||||||
&& !AbstractNullabilityChecker.isSubtypeOfAny(extensionTypeContext, subType) -> return false
|
!AbstractNullabilityChecker.isSubtypeOfAny(extensionTypeContext, subType) -> {
|
||||||
|
return false
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Foo <: T? (T is contained in invariant or contravariant positions of a return type) -- Foo <: T
|
* Foo <: T? (T is contained in invariant or contravariant positions of a return type) -- Foo <: T
|
||||||
* Example:
|
* Example:
|
||||||
@@ -236,7 +239,6 @@ abstract class TypeCheckerStateForConstraintSystem(
|
|||||||
*/
|
*/
|
||||||
typeVariable.isMarkedNullable() -> {
|
typeVariable.isMarkedNullable() -> {
|
||||||
val typeVariableTypeConstructor = typeVariable.typeConstructor()
|
val typeVariableTypeConstructor = typeVariable.typeConstructor()
|
||||||
val subTypeConstructor = subType.typeConstructor()
|
|
||||||
val needToMakeDefNotNull = subTypeConstructor.isTypeVariable() ||
|
val needToMakeDefNotNull = subTypeConstructor.isTypeVariable() ||
|
||||||
typeVariableTypeConstructor !is TypeVariableTypeConstructorMarker ||
|
typeVariableTypeConstructor !is TypeVariableTypeConstructorMarker ||
|
||||||
!typeVariableTypeConstructor.isContainedInInvariantOrContravariantPositions()
|
!typeVariableTypeConstructor.isContainedInInvariantOrContravariantPositions()
|
||||||
|
|||||||
-23
@@ -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
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
|
|
||||||
// FILE: JavaClass.java
|
// FILE: JavaClass.java
|
||||||
|
|||||||
Reference in New Issue
Block a user