diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerStateForConstraintSystem.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerStateForConstraintSystem.kt index 3052ed48e67..11ef367b848 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerStateForConstraintSystem.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerStateForConstraintSystem.kt @@ -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() diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.fir.kt deleted file mode 100644 index 6dc9246aa0e..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// FULL_JDK - -// FILE: JavaClass.java -import java.util.function.Supplier; -import org.jetbrains.annotations.NotNull; - -public class JavaClass { - public static void consume(@NotNull E value) {} - public static void compute(Supplier<@NotNull E> computable) {} -} - -// FILE: KotlinMain.kt -fun test1() { - JavaClass.compute { 42.apply {} } -} - -fun test2() { - JavaClass.compute { if (true) 42 else 42 } -} - -fun test3() { - 42.apply(JavaClass::consume) -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.kt index a58bb08e214..0b106f875e4 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/supplier.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FULL_JDK // FILE: JavaClass.java