mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java: report more "variable might have been assigned to" problems
GitOrigin-RevId: 030936b065bb00b504a69bc08ad39ae8a28cad6f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
319b584d15
commit
97de4512b7
@@ -2624,16 +2624,14 @@ public final class ControlFlowUtil {
|
||||
}
|
||||
|
||||
public static @NotNull Collection<VariableInfo> getInitializedTwice(@NotNull ControlFlow flow, int startOffset, int endOffset) {
|
||||
Collection<VariableInfo> result = new HashSet<>();
|
||||
while (startOffset < endOffset) {
|
||||
InitializedTwiceClientVisitor visitor = new InitializedTwiceClientVisitor(flow, startOffset);
|
||||
depthFirstSearch(flow, visitor, startOffset, endOffset);
|
||||
Collection<VariableInfo> result = visitor.getResult();
|
||||
if (!result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
result.addAll(visitor.getResult());
|
||||
startOffset = findUnprocessed(startOffset, endOffset, visitor);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class InitializedTwiceClientVisitor extends InstructionClientVisitor<Collection<VariableInfo>> {
|
||||
|
||||
+9
@@ -160,6 +160,15 @@ class ForLoop {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void x() {
|
||||
final int a, b;
|
||||
<error descr="Variable 'a' might already have been assigned to">a</error> = a = 0;
|
||||
for (;; b = 0) {
|
||||
<error descr="Variable 'b' might already have been assigned to">b</error> = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// IDEA-186305
|
||||
class Asserts {
|
||||
|
||||
Reference in New Issue
Block a user