mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda effectively final: ignore variables defined inside lambda (IDEA-89818)
This commit is contained in:
+1
-1
@@ -694,7 +694,7 @@ public class HighlightControlFlowUtil {
|
||||
return highlightInfo;
|
||||
} else {
|
||||
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(context, PsiLambdaExpression.class);
|
||||
if (lambdaExpression != null) {
|
||||
if (lambdaExpression != null && !PsiTreeUtil.isAncestor(lambdaExpression, variable, true)) {
|
||||
boolean effectivelyFinal;
|
||||
if (variable instanceof PsiParameter) {
|
||||
final PsiElement parent = variable.getParent();
|
||||
|
||||
+21
@@ -70,3 +70,24 @@ public class XXX {
|
||||
foo(() -> <error descr="Variable used in lambda expression should be effectively final">y</error>=1);
|
||||
}
|
||||
}
|
||||
|
||||
class Sample {
|
||||
public static void main(String[] args) {
|
||||
Runnable runnable = () -> {
|
||||
Integer i;
|
||||
if (true) {
|
||||
i = 111;
|
||||
System.out.println(i);
|
||||
}
|
||||
};
|
||||
|
||||
Runnable runnable2 = () -> {
|
||||
Integer i2 = 333;
|
||||
i2 = 444;
|
||||
System.out.println(i2);
|
||||
};
|
||||
|
||||
runnable.run(); // prints 111
|
||||
runnable2.run(); // prints 444
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user