DFA control flow: do not leak this for nested class constructor

GitOrigin-RevId: a5c8e571dac99819b9f058db753f3a41e1025aac
This commit is contained in:
Tagir Valeev
2019-07-11 13:51:26 +03:00
committed by intellij-monorepo-bot
parent 71e46b99bc
commit 23063d2a84
2 changed files with 19 additions and 1 deletions
@@ -1852,7 +1852,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
qualifier.accept(this);
} else {
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(expression.getType());
if (aClass != null) {
if (aClass != null && !aClass.hasModifierProperty(PsiModifier.STATIC)) {
PsiClass outerClass = aClass.getContainingClass();
if (outerClass != null && InheritanceUtil.hasEnclosingInstanceInScope(outerClass, expression, true, false)) {
qualifierValue = myFactory.getVarFactory().createThisValue(outerClass);
@@ -27,6 +27,16 @@ class Tester
System.err.println("Is false");
}
private Tester(int i)
{
// nested class: should not drop locality ('this' is not leaked)
new Nested();
if (<warning descr="Condition 'flag' is always 'false'">flag</warning>)
System.err.println("Is true.");
else
System.err.println("Is false");
}
class Inner
{
Inner()
@@ -34,4 +44,12 @@ class Tester
flag = true;
}
}
static class Nested
{
Nested()
{
<error descr="Non-static field 'flag' cannot be referenced from a static context">flag</error> = true; // cannot access flag
}
}
}