mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Extends PyConstantExpressionEvaluator.evaluateBoolean to work for integers and use it.
This commit is contained in:
@@ -394,7 +394,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
boolean isStaticallyTrue = false;
|
||||
if (condition != null) {
|
||||
condition.accept(this);
|
||||
isStaticallyTrue = (PyConstantExpressionEvaluator.evaluate(condition) == Boolean.TRUE);
|
||||
isStaticallyTrue = PyConstantExpressionEvaluator.evaluateBoolean(condition, false);
|
||||
}
|
||||
final Instruction head = myBuilder.prevInstruction;
|
||||
final PyElsePart elsePart = node.getElsePart();
|
||||
@@ -752,7 +752,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
super.visitPyAssertStatement(node);
|
||||
final PyExpression[] args = node.getArguments();
|
||||
// assert False
|
||||
if (args.length >= 1 && PyConstantExpressionEvaluator.evaluate(args[0]) == Boolean.FALSE) {
|
||||
if (args.length >= 1 && !PyConstantExpressionEvaluator.evaluateBoolean(args[0], true)) {
|
||||
abruptFlow(node);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,6 +62,9 @@ public class PyConstantExpressionEvaluator {
|
||||
if (result instanceof Boolean) {
|
||||
return (Boolean)result;
|
||||
}
|
||||
else if (result instanceof Integer) {
|
||||
return ((Integer)result) != 0;
|
||||
}
|
||||
else {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
while 1:
|
||||
a = 1
|
||||
break
|
||||
print(a) # pass
|
||||
@@ -1,5 +1,5 @@
|
||||
fo<caret>o = 10
|
||||
while 1:
|
||||
if 5 in [1, 2, 3]:
|
||||
foo += 10
|
||||
|
||||
b = foo
|
||||
@@ -1,5 +1,5 @@
|
||||
foo = 10
|
||||
while 1:
|
||||
if 5 in [1, 2, 3]:
|
||||
foo = foo + 10
|
||||
|
||||
b = fo<caret>o
|
||||
+4
@@ -188,6 +188,10 @@ public class PyUnboundLocalVariableInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWhileOneBreak() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(TEST_DIRECTORY + getTestName(false) + ".py");
|
||||
myFixture.enableInspections(PyUnboundLocalVariableInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user