Unused symbol: do not use body of function literal as scope for members
So #KT-10546 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4b25317ecb
commit
7ae722492f
@@ -829,12 +829,20 @@ public class KtPsiUtil {
|
|||||||
return (KtElement) parent;
|
return (KtElement) parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (current instanceof KtBlockExpression || current instanceof KtParameter) {
|
if (current instanceof KtParameter) {
|
||||||
return (KtElement) current;
|
return (KtElement) current;
|
||||||
}
|
}
|
||||||
if (current instanceof KtValueArgument) {
|
if (current instanceof KtValueArgument) {
|
||||||
// for members, value argument is never enough, see KT-10546
|
// 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) {
|
if (current instanceof KtDelegatedSuperTypeEntry) {
|
||||||
PsiElement grandParent = current.getParent().getParent();
|
PsiElement grandParent = current.getParent().getParent();
|
||||||
|
|||||||
@@ -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 <caret>value = x + y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xs.forEach {
|
||||||
|
println("value: " + it.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun testDC(): String {
|
||||||
|
val x = run {
|
||||||
|
object {
|
||||||
|
val <caret>users = "XXX"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.users
|
||||||
|
}
|
||||||
@@ -1868,6 +1868,18 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("internal.kt")
|
||||||
public void testInternal() throws Exception {
|
public void testInternal() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedSymbol/internal.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedSymbol/internal.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user