Fix using qualified this with labeled function literals

#KT-9251 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-04-17 05:18:17 +03:00
parent b17b3f4c63
commit b60efab62e
4 changed files with 35 additions and 12 deletions
@@ -182,8 +182,7 @@ object LabelResolver {
} }
else if (size == 0) { else if (size == 0) {
val element = resolveNamedLabel(labelName, targetLabel, context.trace) val element = resolveNamedLabel(labelName, targetLabel, context.trace)
if (element is KtFunctionLiteral) { val declarationDescriptor = context.trace.bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, element]
val declarationDescriptor = context.trace.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
if (declarationDescriptor is FunctionDescriptor) { if (declarationDescriptor is FunctionDescriptor) {
val thisReceiver = declarationDescriptor.extensionReceiverParameter val thisReceiver = declarationDescriptor.extensionReceiverParameter
if (thisReceiver != null) { if (thisReceiver != null) {
@@ -196,10 +195,6 @@ object LabelResolver {
context.trace.report(UNRESOLVED_REFERENCE.on(targetLabel, targetLabel)) context.trace.report(UNRESOLVED_REFERENCE.on(targetLabel, targetLabel))
} }
} }
else {
context.trace.report(UNRESOLVED_REFERENCE.on(targetLabel, targetLabel))
}
}
else { else {
BindingContextUtils.reportAmbiguousLabel(context.trace, targetLabel, declarationsByLabel) BindingContextUtils.reportAmbiguousLabel(context.trace, targetLabel, declarationsByLabel)
} }
@@ -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 <!NO_THIS!>this@lambda<!>
}
}
@@ -0,0 +1,5 @@
package
public val funLit: kotlin.String.() -> kotlin.Unit
public fun lambda(): kotlin.Unit
public fun test(): kotlin.Unit
@@ -12670,6 +12670,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName); 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") @TestMetadata("labelsMustBeNamed.kt")
public void testLabelsMustBeNamed() throws Exception { public void testLabelsMustBeNamed() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt");