diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt index 7c4be7139a7..a00bc6ee41d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt @@ -182,19 +182,14 @@ object LabelResolver { } else if (size == 0) { val element = resolveNamedLabel(labelName, targetLabel, context.trace) - if (element is KtFunctionLiteral) { - val declarationDescriptor = context.trace.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element) - if (declarationDescriptor is FunctionDescriptor) { - val thisReceiver = declarationDescriptor.extensionReceiverParameter - if (thisReceiver != null) { - context.trace.record(LABEL_TARGET, targetLabel, element) - context.trace.record(REFERENCE_TARGET, referenceExpression, declarationDescriptor) - } - return LabeledReceiverResolutionResult.labelResolutionSuccess(thisReceiver) - } - else { - context.trace.report(UNRESOLVED_REFERENCE.on(targetLabel, targetLabel)) + val declarationDescriptor = context.trace.bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, element] + if (declarationDescriptor is FunctionDescriptor) { + val thisReceiver = declarationDescriptor.extensionReceiverParameter + if (thisReceiver != null) { + context.trace.record(LABEL_TARGET, targetLabel, element) + context.trace.record(REFERENCE_TARGET, referenceExpression, declarationDescriptor) } + return LabeledReceiverResolutionResult.labelResolutionSuccess(thisReceiver) } else { context.trace.report(UNRESOLVED_REFERENCE.on(targetLabel, targetLabel)) diff --git a/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.kt b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.kt new file mode 100644 index 00000000000..c058084c4cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +val funLit = lambda@ fun String.() { + val d1 = this@lambda +} + +fun test() { + val funLit = lambda@ fun String.(): String { + return this@lambda + } +} + +fun lambda() { + val funLit = lambda@ fun String.(): String { + return this@lambda + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.txt b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.txt new file mode 100644 index 00000000000..de58f687da6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.txt @@ -0,0 +1,5 @@ +package + +public val funLit: kotlin.String.() -> kotlin.Unit +public fun lambda(): kotlin.Unit +public fun test(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 332e6528d2e..a9c960b9c11 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12670,6 +12670,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("labeledFunctionLiteral.kt") + public void testLabeledFunctionLiteral() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.kt"); + doTest(fileName); + } + @TestMetadata("labelsMustBeNamed.kt") public void testLabelsMustBeNamed() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt");