[FIR] Consider ConeConstraintSystemHasContradiction as a good reason for DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE error

This commit is contained in:
Dmitriy Novozhilov
2022-11-21 17:39:27 +02:00
committed by Space Team
parent 9b7b517f43
commit 06e88b559a
9 changed files with 33 additions and 63 deletions
@@ -7,7 +7,7 @@ interface A {
fun getA(): A? = null fun getA(): A? = null
val x by <!NEW_INFERENCE_ERROR!>lazy { val x by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!>lazy {
(getA() ?: error("error")).list.associateBy { (getA() ?: error("error")).list.associateBy {
it it
} }
@@ -18,10 +18,7 @@ import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall
import org.jetbrains.kotlin.fir.expressions.arguments import org.jetbrains.kotlin.fir.expressions.arguments
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError import org.jetbrains.kotlin.fir.resolve.diagnostics.*
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableWrongReceiver
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
@@ -82,18 +79,17 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() {
) )
} }
return when (val diagnostic = errorNamedReference.diagnostic) { var errorReported = true
is ConeUnresolvedNameError -> { when (val diagnostic = errorNamedReference.diagnostic) {
reporter.reportOn( is ConeUnresolvedNameError -> reporter.reportOn(
errorNamedReference.source, errorNamedReference.source,
FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING,
expectedFunctionSignature, expectedFunctionSignature,
delegateType, delegateType,
delegateDescription, delegateDescription,
context context
) )
true
}
is ConeAmbiguityError -> { is ConeAmbiguityError -> {
if (diagnostic.applicability.isSuccess) { if (diagnostic.applicability.isSuccess) {
// Match is successful but there are too many matches! So we report DELEGATE_SPECIAL_FUNCTION_AMBIGUITY. // Match is successful but there are too many matches! So we report DELEGATE_SPECIAL_FUNCTION_AMBIGUITY.
@@ -107,25 +103,24 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() {
} else { } else {
reportInapplicableDiagnostics(diagnostic.candidates.map { it.symbol }) reportInapplicableDiagnostics(diagnostic.candidates.map { it.symbol })
} }
true
} }
is ConeInapplicableWrongReceiver -> {
reporter.reportOn( is ConeInapplicableWrongReceiver -> reporter.reportOn(
errorNamedReference.source, errorNamedReference.source,
FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING,
expectedFunctionSignature, expectedFunctionSignature,
delegateType, delegateType,
delegateDescription, delegateDescription,
context context
) )
true is ConeInapplicableCandidateError -> reportInapplicableDiagnostics(listOf(diagnostic.candidate.symbol))
is ConeConstraintSystemHasContradiction -> reportInapplicableDiagnostics(listOf(diagnostic.candidate.symbol))
else -> {
errorReported = false
} }
is ConeInapplicableCandidateError -> {
reportInapplicableDiagnostics(listOf(diagnostic.candidate.symbol))
true
}
else -> false
} }
return errorReported
} }
private fun checkReturnType(functionCall: FirFunctionCall) { private fun checkReturnType(functionCall: FirFunctionCall) {
@@ -24,4 +24,4 @@ class C<R>() {
} }
var c1: Int by C() var c1: Int by C()
var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>C<Number>()<!> var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>C<Number>()<!>
@@ -3,7 +3,7 @@
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
var a: Int by A() var a: Int by A()
var a1 by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A()<!> var a1 by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A()<!>
var b: Int by B() var b: Int by B()
@@ -1,16 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class StringDelegate(val s: String) {
operator fun getValue(a: Any?, p: KProperty<*>): Int = 42
}
// NB no operator
fun String.provideDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this)
operator fun String.getValue(a: Any?, p: KProperty<*>) = this
val test1: String by "OK"
val test2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>"OK"<!>
val test3 by "OK"
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
@@ -1,11 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val c: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String {
return ""
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
@@ -7,6 +7,6 @@ fun interface ReadOnlyProperty<in T, out V> {
} }
class Problem { class Problem {
val variable: Int by <!NEW_INFERENCE_ERROR!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>delegate<!>()<!> // delegate returns `ReadOnlyProperty<Problem, {CharSequence & Int}>` val variable: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_ERROR!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>delegate<!>()<!> // delegate returns `ReadOnlyProperty<Problem, {CharSequence & Int}>`
fun <T : CharSequence> delegate() = null <!CAST_NEVER_SUCCEEDS!>as<!> ReadOnlyProperty<Problem, T> fun <T : CharSequence> delegate() = null <!CAST_NEVER_SUCCEEDS!>as<!> ReadOnlyProperty<Problem, T>
} }