diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 5edf6c675a4..72e10ea193f 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -6186,6 +6186,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt"); } + @TestMetadata("provideDelegateOnFunctionalTypeWithThis.kt") + public void testProvideDelegateOnFunctionalTypeWithThis() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt"); + } + @TestMetadata("provideDelegateOperatorDeclaration.kt") public void testProvideDelegateOperatorDeclaration() throws Exception { runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index cfca639bfa5..910b3a3516d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -571,7 +571,7 @@ class DelegatedPropertyResolver( variableDescriptor, delegateExpression, delegateTypeWithoutNonFixedVariables, contextForProvideDelegate ) - if (conventionMethodFound(provideDelegateResults)) { + if (provideDelegateResults.isSuccess) { val provideDelegateDescriptor = provideDelegateResults.resultingDescriptor if (provideDelegateDescriptor.isOperator) { delegateType = inverseSubstitution(provideDelegateDescriptor.returnType, substitutionMap) ?: return null diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.fail b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.fail new file mode 100644 index 00000000000..54d7f40e102 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.fail @@ -0,0 +1,2 @@ +Failures detected in FirBodyResolveTransformerAdapter, file: /provideDelegateOnFunctionalTypeWithThis.fir.kt +Cause: java.lang.ClassCastException: org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl cannot be cast to org.jetbrains.kotlin.fir.types.FirResolvedTypeRef diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt new file mode 100644 index 00000000000..9a645ad5a63 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WITH_RUNTIME + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class CaptureContext(val capture: (A) -> Unit) : ReadOnlyProperty Unit> { + override fun getValue(thisRef: A, property: KProperty<*>) = { -> capture(thisRef) } +} +operator fun ((A) -> Unit).provideDelegate(thisRef: A, property: KProperty<*>) = CaptureContext(this) + +fun wrong(arg: Wrong) {} +class Wrong + +class Right { + val prop: () -> Unit by ::wrong +} + +fun box(): String { + Right().prop() + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt new file mode 100644 index 00000000000..9a645ad5a63 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// WITH_RUNTIME + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class CaptureContext(val capture: (A) -> Unit) : ReadOnlyProperty Unit> { + override fun getValue(thisRef: A, property: KProperty<*>) = { -> capture(thisRef) } +} +operator fun ((A) -> Unit).provideDelegate(thisRef: A, property: KProperty<*>) = CaptureContext(this) + +fun wrong(arg: Wrong) {} +class Wrong + +class Right { + val prop: () -> Unit by ::wrong +} + +fun box(): String { + Right().prop() + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.txt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.txt new file mode 100644 index 00000000000..4a731e19cdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.txt @@ -0,0 +1,29 @@ +package + +public fun box(): kotlin.String +public fun wrong(/*0*/ arg: Wrong): kotlin.Unit +public operator fun ((A) -> kotlin.Unit).provideDelegate(/*0*/ thisRef: A, /*1*/ property: kotlin.reflect.KProperty<*>): CaptureContext + +public final class CaptureContext : kotlin.properties.ReadOnlyProperty kotlin.Unit> { + public constructor CaptureContext(/*0*/ capture: (A) -> kotlin.Unit) + public final val capture: (A) -> kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun getValue(/*0*/ thisRef: A, /*1*/ property: kotlin.reflect.KProperty<*>): () -> kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Right { + public constructor Right() + public final val prop: () -> kotlin.Unit + 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 final class Wrong { + public constructor Wrong() + 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 +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt index 6b90d11d8f5..d2fa2d829b6 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt @@ -11,7 +11,7 @@ operator fun String.provideDelegate(receiver: Any?, p: Any) = Delegate() var test1: String by Delegate() var test2: String by Delegate() -var test3: String by "OK" +var test3: String by "OK" var test4: String by "OK".provideDelegate(null, "") var test5: String by "OK".provideDelegate(null, "") \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 53d49da59d6..dc6ea1a20cc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6193,6 +6193,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt"); } + @TestMetadata("provideDelegateOnFunctionalTypeWithThis.kt") + public void testProvideDelegateOnFunctionalTypeWithThis() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt"); + } + @TestMetadata("provideDelegateOperatorDeclaration.kt") public void testProvideDelegateOperatorDeclaration() throws Exception { runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index e6966540eab..edbeaba0daf 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -6188,6 +6188,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.kt"); } + @TestMetadata("provideDelegateOnFunctionalTypeWithThis.kt") + public void testProvideDelegateOnFunctionalTypeWithThis() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.kt"); + } + @TestMetadata("provideDelegateOperatorDeclaration.kt") public void testProvideDelegateOperatorDeclaration() throws Exception { runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.kt");