LocalsOrMyInstanceFieldsControlFlowPolicy: allow parentheses

See also IDEA-156926, JDK-8156180
This commit is contained in:
Tagir Valeev
2018-06-07 17:55:13 +07:00
parent 67d2b6ca2b
commit 51af524343
2 changed files with 5 additions and 4 deletions
@@ -17,6 +17,7 @@
package com.intellij.psi.controlFlow;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
@@ -55,7 +56,7 @@ public class LocalsOrMyInstanceFieldsControlFlowPolicy implements ControlFlowPol
* the reference actually resolves to variable.
*/
public static boolean isLocalOrMyInstanceReference(PsiReferenceExpression variableReference) {
PsiExpression qualifierExpression = variableReference.getQualifierExpression();
PsiExpression qualifierExpression = PsiUtil.skipParenthesizedExprDown(variableReference.getQualifierExpression());
// JLS 16: "Such an assignment is defined to occur if and only if either the simple name of the variable
// (or, for a field, its simple name qualified by this) occurs on the left hand side of an assignment operator"
// Qualified this is not allowed by spec
@@ -255,10 +255,10 @@ class QualifiedThis {
class ParenthesizedThis {
final int x;
final int y = (this).x + 1; // allowed as qualifier is not naked 'this'!
final int y = <error descr="Variable '(this).x' might not have been initialized">(this).x</error> + 1; // javac allows this?
ParenthesizedThis() {
<error descr="Cannot assign a value to final variable 'x'">(this).x</error> = 5;
this.x = 6;
(this).x = 5;
<error descr="Variable 'x' might already have been assigned to">this.x</error> = 6;
}
}