FIR: Avoid reporting inference errors from DelegatedPropertyConstraintPosition

All necessary diagnostics have already been reported through the checkers
This commit is contained in:
Denis.Zharkov
2021-05-26 11:33:16 +03:00
committed by TeamCityServer
parent 43f3fe1ebe
commit 6136526a3a
14 changed files with 28 additions and 24 deletions
@@ -272,6 +272,10 @@ private fun ConstraintSystemError.toDiagnostic(
upperConeType,
)
}
is DelegatedPropertyConstraintPosition<*> -> {
errorsToIgnore.add(this)
return null
}
else -> null
}
}
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.DelegatedPropertyConstraintPosition
import org.jetbrains.kotlin.util.OperatorNameConventions
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -113,7 +113,7 @@ class FirDelegatedPropertyInferenceSession(
val unsubstitutedReturnType = accessor.returnTypeRef.coneType
val substitutedReturnType = substitutor.substituteOrSelf(unsubstitutedReturnType)
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType!!, SimpleConstraintSystemConstraintPosition)
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType!!, DelegatedPropertyConstraintPosition(callInfo.callSite))
}
addConstraintForThis(commonSystem)
@@ -125,7 +125,7 @@ class FirDelegatedPropertyInferenceSession(
val unsubstitutedParameterType = accessor.valueParameters.getOrNull(2)?.returnTypeRef?.coneType ?: return
val substitutedReturnType = substitutor.substituteOrSelf(unsubstitutedParameterType)
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType!!, SimpleConstraintSystemConstraintPosition)
commonSystem.addSubtypeConstraint(expectedType!!, substitutedReturnType, DelegatedPropertyConstraintPosition(callInfo.callSite))
}
addConstraintForThis(commonSystem)
@@ -141,7 +141,7 @@ class FirDelegatedPropertyInferenceSession(
} ?: components.session.builtinTypes.nullableNothingType.type
val valueParameterForThis = (symbol as? FirFunctionSymbol<*>)?.fir?.valueParameters?.firstOrNull() ?: return
val substitutedType = substitutor.substituteOrSelf(valueParameterForThis.returnTypeRef.coneType)
commonSystem.addSubtypeConstraint(typeOfThis, substitutedType, SimpleConstraintSystemConstraintPosition)
commonSystem.addSubtypeConstraint(typeOfThis, substitutedType, DelegatedPropertyConstraintPosition(callInfo.callSite))
}
override fun <T> writeOnlyStubs(call: T): Boolean where T : FirResolvable, T : FirStatement = false
@@ -68,7 +68,7 @@ abstract class LambdaArgumentConstraintPosition<T>(val lambda: T) : ConstraintPo
}
}
abstract class DelegatedPropertyConstraintPosition<T>(val topLevelCall: T) : ConstraintPosition() {
open class DelegatedPropertyConstraintPosition<T>(val topLevelCall: T) : ConstraintPosition() {
override fun toString(): String = "Constraint from call $topLevelCall for delegated property"
}
@@ -16,7 +16,7 @@ class B<R>() {
}
var b1: Int by B()
var b2: Int by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>B<Number>()<!>
var b2: Int by B<Number>()
class C<R>() {
operator fun getValue(t: Any?, p: KProperty<*>): R = null!!
@@ -3,8 +3,8 @@ package foo
import kotlin.reflect.KProperty
class A {
var a5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>MyProperty1()<!>
var b5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>getMyProperty1()<!>
var a5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>MyProperty1()<!>
var b5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>getMyProperty1()<!>
}
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
@@ -52,12 +52,12 @@ class MyProperty2<T> {
//--------------------------
class A3 {
var a3: String by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>MyProperty3()<!>
var b3: String by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>getMyProperty3()<!>
var a3: String by MyProperty3()
var b3: String by getMyProperty3()
}
var c3: String by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>getMyProperty3()<!>
var d3: String by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>MyProperty3()<!>
var c3: String by getMyProperty3()
var d3: String by MyProperty3()
fun <A> getMyProperty3() = MyProperty3<A>()
@@ -5,7 +5,7 @@ class A {
val p1 by this
get
var p2 by <!NEW_INFERENCE_ERROR!>this<!>
var p2 by this
<!ACCESSOR_FOR_DELEGATED_PROPERTY!>get() = ""<!>
operator fun getValue(a: Any?, p: Any?) = ""
@@ -9,5 +9,5 @@ object T2 {
operator fun <T> Foo<T>.getValue(receiver: String, p: Any?): T = TODO()
val String.test1: String by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>delegate<!>()
val test2: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>delegate<!>()<!>
val test2: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>delegate<!>()<!>
}
@@ -4,10 +4,10 @@
import kotlin.reflect.KProperty
class D {
var c: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!>Delegate()<!>
var c: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
}
var cTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!>Delegate()<!>
var cTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
class A
@@ -6,7 +6,7 @@ import kotlin.reflect.KProperty
open class Base
class Derived: Base()
var a: Derived by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>A()<!>
var a: Derived by A()
class A {
operator fun getValue(t: Any?, p: KProperty<*>): Derived {
@@ -4,10 +4,10 @@
import kotlin.reflect.KProperty
class A {
var a: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!>Delegate()<!>
var a: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
}
var aTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!>Delegate()<!>
var aTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
@@ -19,6 +19,6 @@ public class J {
// FILE: k.kt
var A by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>J.staticNN<!>
var A by J.staticNN
var B by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>J.staticN<!>
var C by <!NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>J.staticJ<!>
var C by J.staticJ
@@ -7,6 +7,6 @@ fun interface ReadOnlyProperty<in T, out V> {
}
class Problem {
val variable: Int by delegate() // delegate returns `ReadOnlyProperty<Problem, {CharSequence & Int}>`
val variable: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, NEW_INFERENCE_ERROR, NEW_INFERENCE_ERROR!>delegate()<!> // delegate returns `ReadOnlyProperty<Problem, {CharSequence & Int}>`
fun <T : CharSequence> delegate() = null as ReadOnlyProperty<Problem, T>
}
}
@@ -9,4 +9,4 @@ fun interface ReadOnlyProperty<in T, out V> {
class Problem {
val variable: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!TYPE_MISMATCH!>delegate<!>()<!> // delegate returns `ReadOnlyProperty<Problem, {CharSequence & Int}>`
fun <T : CharSequence> delegate() = null <!CAST_NEVER_SUCCEEDS!>as<!> ReadOnlyProperty<Problem, T>
}
}