diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java index 9efd24a58c1..e3236b67f4b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java @@ -829,12 +829,20 @@ public class KtPsiUtil { return (KtElement) parent; } } - if (current instanceof KtBlockExpression || current instanceof KtParameter) { + if (current instanceof KtParameter) { return (KtElement) current; } if (current instanceof KtValueArgument) { // for members, value argument is never enough, see KT-10546 - if (!isNonLocalCallable) return (KtElement) current; + if (!isNonLocalCallable) { + return (KtElement) current; + } + } + if (current instanceof KtBlockExpression) { + // For members also not applicable if has function literal parent + if (!isNonLocalCallable || !(current.getParent() instanceof KtFunctionLiteral)) { + return (KtElement) current; + } } if (current instanceof KtDelegatedSuperTypeEntry) { PsiElement grandParent = current.getParent().getParent(); diff --git a/idea/testData/inspectionsLocal/unusedSymbol/inAnonymousDeeply.kt b/idea/testData/inspectionsLocal/unusedSymbol/inAnonymousDeeply.kt new file mode 100644 index 00000000000..e9055ee9123 --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/inAnonymousDeeply.kt @@ -0,0 +1,16 @@ +// PROBLEM: none +// WITH_RUNTIME + +fun foo() { + val xs = listOf(1, 2, 3).flatMap { x -> + listOf(3, 4, 5).map { y -> + object { + val value = x + y + } + } + } + + xs.forEach { + println("value: " + it.value) + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/unusedSymbol/inAnonymousRunWrapped.kt b/idea/testData/inspectionsLocal/unusedSymbol/inAnonymousRunWrapped.kt new file mode 100644 index 00000000000..a14a621f9cb --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/inAnonymousRunWrapped.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +// WITH_RUNTIME + +fun testDC(): String { + val x = run { + object { + val users = "XXX" + } + } + + return x.users +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 546ceb5815c..3d3562ed4cb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -1868,6 +1868,18 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { doTest(fileName); } + @TestMetadata("inAnonymousDeeply.kt") + public void testInAnonymousDeeply() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedSymbol/inAnonymousDeeply.kt"); + doTest(fileName); + } + + @TestMetadata("inAnonymousRunWrapped.kt") + public void testInAnonymousRunWrapped() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedSymbol/inAnonymousRunWrapped.kt"); + doTest(fileName); + } + @TestMetadata("internal.kt") public void testInternal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedSymbol/internal.kt");