mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
"might not have been initialized" adjusted for lambdas inside anonymous (IDEA-130468)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user