Put fix in 9123c4f73baf77f8a50dede6c890c46f5ffafd6c under the inference compatibility flag
This commit is contained in:
+5
@@ -10689,6 +10689,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag.kt")
|
||||
public void testNullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overApproximationForInCaptured.kt")
|
||||
public void testOverApproximationForInCaptured() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.kt");
|
||||
|
||||
+8
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.NoMutableState
|
||||
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintIncorporator
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
|
||||
@@ -24,7 +25,13 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
||||
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {}
|
||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
||||
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle, ConeConstraintSystemUtilContext)
|
||||
private val injector = ConstraintInjector(incorporator, approximator)
|
||||
private val injector = ConstraintInjector(
|
||||
incorporator,
|
||||
approximator,
|
||||
object : InferenceCompatibilityChecker {
|
||||
override val isCompatibilityModeEnabled = true
|
||||
}
|
||||
)
|
||||
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
|
||||
|
||||
val constraintSystemFactory = ConstraintSystemFactory()
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve
|
||||
import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMapper
|
||||
import org.jetbrains.kotlin.container.*
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityCheckerImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
import org.jetbrains.kotlin.resolve.checkers.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||
@@ -107,6 +108,7 @@ abstract class PlatformConfiguratorBase(
|
||||
|
||||
override fun configureModuleDependentCheckers(container: StorageComponentContainer) {
|
||||
container.useImpl<ExperimentalMarkerDeclarationAnnotationChecker>()
|
||||
container.useImpl<InferenceCompatibilityCheckerImpl>()
|
||||
}
|
||||
|
||||
fun configureExtensionsAndCheckers(container: StorageComponentContainer) {
|
||||
|
||||
+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
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
|
||||
class InferenceCompatibilityCheckerImpl(val languageVersionSettings: LanguageVersionSettings) : InferenceCompatibilityChecker {
|
||||
override val isCompatibilityModeEnabled: Boolean
|
||||
get() = languageVersionSettings.getFeatureSupport(LanguageFeature.InferenceCompatibility) == LanguageFeature.State.ENABLED
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS -REDUNDANT_PROJECTION
|
||||
// !LANGUAGE: +InferenceCompatibility
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<L> extends Bar<L> {
|
||||
public Foo(L x) {
|
||||
super(x);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun <T : Any> Bar<T>.foo(): T = null as T
|
||||
fun <T : Any> Bar<T?>.bar(): T = null as T
|
||||
fun <T : Any> Foo<T>.boo1(): T = null as T
|
||||
fun <T : Any> Foo<T?>.boo2(): T = null as T
|
||||
|
||||
open class Bar<out K>(val x: K)
|
||||
|
||||
fun main(x: Foo<out Number?>, y: Bar<out Number?>, z1: Foo<out Number>, z2: Bar<out Number>) {
|
||||
x.foo()
|
||||
x.bar()
|
||||
x.boo1()
|
||||
x.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
|
||||
y.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
y.bar()
|
||||
y.<!INAPPLICABLE_CANDIDATE!>boo1<!>()
|
||||
y.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
|
||||
z1.foo()
|
||||
z1.bar()
|
||||
z1.boo1()
|
||||
z1.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
|
||||
z2.foo()
|
||||
z2.bar()
|
||||
z2.<!INAPPLICABLE_CANDIDATE!>boo1<!>()
|
||||
z2.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
}
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS -REDUNDANT_PROJECTION
|
||||
// !LANGUAGE: +InferenceCompatibility
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<L> extends Bar<L> {
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS -REDUNDANT_PROJECTION
|
||||
// !LANGUAGE: -InferenceCompatibility
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<L> extends Bar<L> {
|
||||
public Foo(L x) {
|
||||
super(x);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun <T : Any> Bar<T>.foo(): T = null as T
|
||||
fun <T : Any> Bar<T?>.bar(): T = null as T
|
||||
fun <T : Any> Foo<T>.boo1(): T = null as T
|
||||
fun <T : Any> Foo<T?>.boo2(): T = null as T
|
||||
|
||||
open class Bar<out K>(val x: K)
|
||||
|
||||
fun main(x: Foo<out Number?>, y: Bar<out Number?>, z1: Foo<out Number>, z2: Bar<out Number>) {
|
||||
x.foo()
|
||||
x.bar()
|
||||
x.boo1()
|
||||
x.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
|
||||
y.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
y.bar()
|
||||
y.<!INAPPLICABLE_CANDIDATE!>boo1<!>()
|
||||
y.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
|
||||
z1.foo()
|
||||
z1.bar()
|
||||
z1.boo1()
|
||||
z1.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
|
||||
z2.foo()
|
||||
z2.bar()
|
||||
z2.<!INAPPLICABLE_CANDIDATE!>boo1<!>()
|
||||
z2.<!INAPPLICABLE_CANDIDATE!>boo2<!>()
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS -REDUNDANT_PROJECTION
|
||||
// !LANGUAGE: -InferenceCompatibility
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<L> extends Bar<L> {
|
||||
public Foo(L x) {
|
||||
super(x);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun <T : Any> Bar<T>.foo(): T = null as T
|
||||
fun <T : Any> Bar<T?>.bar(): T = null as T
|
||||
fun <T : Any> Foo<T>.boo1(): T = null as T
|
||||
fun <T : Any> Foo<T?>.boo2(): T = null as T
|
||||
|
||||
open class Bar<out K>(val x: K)
|
||||
|
||||
fun main(x: Foo<out Number?>, y: Bar<out Number?>, z1: Foo<out Number>, z2: Bar<out Number>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x.foo()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number?")!>x.boo1()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>x.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>y.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>foo<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>y.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>y.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo1<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>y.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Number..kotlin.Number?)")!>z1.foo()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z1.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z1.boo1()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>z1.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z2.foo()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z2.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>z2.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo1<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>z2.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package
|
||||
|
||||
public fun main(/*0*/ x: Foo<out kotlin.Number?>, /*1*/ y: Bar<out kotlin.Number?>, /*2*/ z1: Foo<out kotlin.Number>, /*3*/ z2: Bar<out kotlin.Number>): kotlin.Unit
|
||||
public fun </*0*/ T : kotlin.Any> Bar<T?>.bar(): T
|
||||
public fun </*0*/ T : kotlin.Any> Foo<T>.boo1(): T
|
||||
public fun </*0*/ T : kotlin.Any> Foo<T?>.boo2(): T
|
||||
public fun </*0*/ T : kotlin.Any> Bar<T>.foo(): T
|
||||
|
||||
public open class Bar</*0*/ out K> {
|
||||
public constructor Bar</*0*/ out K>(/*0*/ x: K)
|
||||
public final val x: K
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class Foo</*0*/ L : kotlin.Any!> : Bar<L!> {
|
||||
public constructor Foo</*0*/ L : kotlin.Any!>(/*0*/ x: L!)
|
||||
public final override /*1*/ /*fake_override*/ val x: L!
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -10696,6 +10696,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag.kt")
|
||||
public void testNullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overApproximationForInCaptured.kt")
|
||||
public void testOverApproximationForInCaptured() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.kt");
|
||||
|
||||
Generated
+5
@@ -10691,6 +10691,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag.kt")
|
||||
public void testNullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariableWithDisabledComplatibilityFlag.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overApproximationForInCaptured.kt")
|
||||
public void testOverApproximationForInCaptured() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.kt");
|
||||
|
||||
Reference in New Issue
Block a user