diff --git a/compiler/fir/analysis-tests/testData/resolve/properties/lazyValWithElvisToNothingInside.kt b/compiler/fir/analysis-tests/testData/resolve/properties/lazyValWithElvisToNothingInside.kt index 91c9b2495a2..f6661721113 100644 --- a/compiler/fir/analysis-tests/testData/resolve/properties/lazyValWithElvisToNothingInside.kt +++ b/compiler/fir/analysis-tests/testData/resolve/properties/lazyValWithElvisToNothingInside.kt @@ -7,7 +7,7 @@ interface A { fun getA(): A? = null -val x by lazy { +val x by lazy { (getA() ?: error("error")).list.associateBy { it } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt index 36c5a83dfd2..dda2a2e7bfd 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt @@ -18,10 +18,7 @@ import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirImplicitInvokeCall import org.jetbrains.kotlin.fir.expressions.arguments import org.jetbrains.kotlin.fir.references.FirErrorNamedReference -import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError -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.resolve.diagnostics.* import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid @@ -82,18 +79,17 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() { ) } - return when (val diagnostic = errorNamedReference.diagnostic) { - is ConeUnresolvedNameError -> { - reporter.reportOn( - errorNamedReference.source, - FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, - expectedFunctionSignature, - delegateType, - delegateDescription, - context - ) - true - } + var errorReported = true + when (val diagnostic = errorNamedReference.diagnostic) { + is ConeUnresolvedNameError -> reporter.reportOn( + errorNamedReference.source, + FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, + expectedFunctionSignature, + delegateType, + delegateDescription, + context + ) + is ConeAmbiguityError -> { if (diagnostic.applicability.isSuccess) { // Match is successful but there are too many matches! So we report DELEGATE_SPECIAL_FUNCTION_AMBIGUITY. @@ -107,25 +103,24 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() { } else { reportInapplicableDiagnostics(diagnostic.candidates.map { it.symbol }) } - true } - is ConeInapplicableWrongReceiver -> { - reporter.reportOn( - errorNamedReference.source, - FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, - expectedFunctionSignature, - delegateType, - delegateDescription, - context - ) - true + + is ConeInapplicableWrongReceiver -> reporter.reportOn( + errorNamedReference.source, + FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, + expectedFunctionSignature, + delegateType, + delegateDescription, + context + ) + 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) { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt index 6c2b0d91eff..b42b011a027 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt @@ -24,4 +24,4 @@ class C() { } var c1: Int by C() -var c2: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt index a76f63ac11f..53629cace64 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt @@ -3,7 +3,7 @@ import kotlin.reflect.KProperty var a: Int by A() -var a1 by A() +var a1 by A() var b: Int by B() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt deleted file mode 100644 index 648295eb2c4..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt +++ /dev/null @@ -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 "OK" -val test3 by "OK" diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt index d92e6ab8bf5..73b980ddbad 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt deleted file mode 100644 index faf7937226b..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -val c: Int by Delegate() - -class Delegate { - operator fun getValue(t: Any?, p: KProperty<*>): String { - return "" - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt index babcd067eb8..9f9edad8154 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt42472.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/kt42472.fir.kt index 7ba4db86fee..d0ea0f7d911 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/kt42472.fir.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/kt42472.fir.kt @@ -7,6 +7,6 @@ fun interface ReadOnlyProperty { } class Problem { - val variable: Int by delegate() // delegate returns `ReadOnlyProperty` + val variable: Int by delegate() // delegate returns `ReadOnlyProperty` fun delegate() = null as ReadOnlyProperty }