"might not have been initialized" adjusted for lambdas inside anonymous (IDEA-130468)

This commit is contained in:
Anna Kozlova
2014-10-24 20:44:56 +02:00
parent 59907085c1
commit 8f67ad587e
3 changed files with 71 additions and 1 deletions

View File

@@ -260,7 +260,7 @@ public class HighlightControlFlowUtil {
}
else {
PsiElement scope = variable instanceof PsiField
? variable.getContainingFile()
? ((PsiField)variable).getContainingClass()
: variable.getParent() != null ? variable.getParent().getParent() : null;
if (scope instanceof PsiCodeBlock && scope.getParent() instanceof PsiSwitchStatement) {
scope = PsiTreeUtil.getParentOfType(scope, PsiCodeBlock.class);

View File

@@ -0,0 +1,66 @@
class Test {
final Runnable runnable;
{
runnable = () -> System.out.println(<error descr="Variable 'runnable' might not have been initialized">runnable</error>);
}
final Runnable runnable1;
{
runnable1 = new Runnable() {
@Override
public void run() {
System.out.println(runnable1);
}
};
}
}
abstract class TestInnerAnonymous {
void foo() {
new Object() {
final Runnable runnable;
{
runnable = () -> System.out.println(<error descr="Variable 'runnable' might not have been initialized">runnable</error>);
}
final Runnable runnable1;
{
runnable1 = new Runnable() {
@Override
public void run() {
System.out.println(runnable1);
}
};
}
};
}
private static class MyObject {
final Runnable runnable;
{
runnable = () -> System.out.println(<error descr="Variable 'runnable' might not have been initialized">runnable</error>);
}
final Runnable runnable1;
{
runnable1 = new Runnable() {
@Override
public void run() {
System.out.println(runnable1);
}
};
}
}
}

View File

@@ -39,6 +39,10 @@ public class LightAdvHighlightingJdk8Test extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testFinalVariableMightNotHaveBeenInitializedInsideLambda() throws Exception {
doTest();
}
private void doTest() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);