diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index b3a59d0fb4b..febf4f949ea 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -5978,6 +5978,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt"); } + @TestMetadata("delegatedExpressionWithLabeledReturnInsideLambda.kt") + public void testDelegatedExpressionWithLabeledReturnInsideLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.kt"); + } + @TestMetadata("differentDelegatedExpressions.kt") public void testDifferentDelegatedExpressions() throws Exception { runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index e6671fba972..f79bc9eb46d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -208,6 +208,10 @@ class KotlinResolutionCallbacksImpl( val lastExpressionArgument = getLastDeparentesizedExpression(psiCallArgument)?.let { lastExpression -> if (expectedReturnType?.isUnit() == true || hasReturnWithoutExpression) return@let null // coercion to Unit + if (lambdaInfo.returnStatements.any { (expression, _) -> expression == lastExpression }) { + return@let null + } + // todo lastExpression can be if without else returnArgumentFound = true val lastExpressionType = trace.getType(lastExpression) diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.kt new file mode 100644 index 00000000000..13953b3e5b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +class Delegate + +operator fun Delegate.getValue(thisRef: Any?, property: kotlin.reflect.KProperty<*>): T = TODO() + +fun createDelegate(f: () -> K): Delegate = TODO() + +fun test() { + val bar: () -> String by createDelegate { + return@createDelegate { "str" } + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.txt new file mode 100644 index 00000000000..01b6bdb671d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.txt @@ -0,0 +1,12 @@ +package + +public fun createDelegate(/*0*/ f: () -> K): Delegate +public fun test(): kotlin.Unit +public operator fun Delegate.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): T + +public final class Delegate { + public constructor Delegate() + 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/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 48e143a64a1..a52809c538a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -5985,6 +5985,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt"); } + @TestMetadata("delegatedExpressionWithLabeledReturnInsideLambda.kt") + public void testDelegatedExpressionWithLabeledReturnInsideLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.kt"); + } + @TestMetadata("differentDelegatedExpressions.kt") public void testDifferentDelegatedExpressions() throws Exception { runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 7d1c15dae00..4e8e5a7ddc0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -5980,6 +5980,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.kt"); } + @TestMetadata("delegatedExpressionWithLabeledReturnInsideLambda.kt") + public void testDelegatedExpressionWithLabeledReturnInsideLambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/delegatedExpressionWithLabeledReturnInsideLambda.kt"); + } + @TestMetadata("differentDelegatedExpressions.kt") public void testDifferentDelegatedExpressions() throws Exception { runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");