Put fix in 9123c4f73baf77f8a50dede6c890c46f5ffafd6c under the inference compatibility flag
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.inference
|
||||
|
||||
interface InferenceCompatibilityChecker {
|
||||
val isCompatibilityModeEnabled: Boolean
|
||||
}
|
||||
+14
-8
@@ -21,6 +21,8 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
|
||||
override val isStubTypeEqualsToAnything: Boolean
|
||||
get() = true
|
||||
|
||||
abstract val isInferenceCompatibilityEnabled: Boolean
|
||||
|
||||
abstract fun isMyTypeVariable(type: SimpleTypeMarker): Boolean
|
||||
|
||||
// super and sub type isSingleClassifierType
|
||||
@@ -209,16 +211,20 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
|
||||
if (typeVariable.isMarkedNullable()) {
|
||||
val typeVariableTypeConstructor = typeVariable.typeConstructor()
|
||||
val subTypeConstructor = subType.typeConstructor()
|
||||
val resultType = if (
|
||||
!subTypeConstructor.isTypeVariable() &&
|
||||
typeVariableTypeConstructor.isTypeVariable() &&
|
||||
(typeVariableTypeConstructor as TypeVariableTypeConstructorMarker).isContainedInInvariantOrContravariantPositions()
|
||||
) {
|
||||
subType.withNullability(false)
|
||||
} else {
|
||||
val needToMakeDefNotNull = subTypeConstructor.isTypeVariable() ||
|
||||
typeVariableTypeConstructor !is TypeVariableTypeConstructorMarker ||
|
||||
!typeVariableTypeConstructor.isContainedInInvariantOrContravariantPositions()
|
||||
|
||||
val resultType = if (needToMakeDefNotNull) {
|
||||
subType.makeDefinitelyNotNullOrNotNull()
|
||||
} else {
|
||||
if (!isInferenceCompatibilityEnabled && subType is CapturedTypeMarker) {
|
||||
subType.withNotNullProjection()
|
||||
} else {
|
||||
subType.withNullability(false)
|
||||
}
|
||||
}
|
||||
if (resultType is CapturedTypeMarker) resultType.withNotNullProjection() else resultType
|
||||
if (isInferenceCompatibilityEnabled && resultType is CapturedTypeMarker) resultType.withNotNullProjection() else resultType
|
||||
} else subType
|
||||
|
||||
is FlexibleTypeMarker -> {
|
||||
|
||||
+5
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.*
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
@@ -19,7 +20,8 @@ import kotlin.math.max
|
||||
|
||||
class ConstraintInjector(
|
||||
val constraintIncorporator: ConstraintIncorporator,
|
||||
val typeApproximator: AbstractTypeApproximator
|
||||
val typeApproximator: AbstractTypeApproximator,
|
||||
val inferenceCompatibilityChecker: InferenceCompatibilityChecker
|
||||
) {
|
||||
private val ALLOWED_DEPTH_DELTA_FOR_INCORPORATION = 1
|
||||
|
||||
@@ -129,6 +131,8 @@ class ConstraintInjector(
|
||||
// We use `var` intentionally to avoid extra allocations as this property is quite "hot"
|
||||
private var possibleNewConstraints: MutableList<Pair<TypeVariableMarker, Constraint>>? = null
|
||||
|
||||
override val isInferenceCompatibilityEnabled = inferenceCompatibilityChecker.isCompatibilityModeEnabled
|
||||
|
||||
private var baseLowerType = position.initialConstraint.a
|
||||
private var baseUpperType = position.initialConstraint.b
|
||||
|
||||
|
||||
Reference in New Issue
Block a user