Improve inVoidContext to take conditional expressions into account.

This commit is contained in:
Max Schaefer
2022-03-30 10:48:01 +01:00
committed by Erik Krogh Kristensen
parent 2f436c800b
commit 47e425a184
3 changed files with 10 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ predicate inVoidContext(Expr e) {
)
or
exists(LogicalBinaryExpr logical | e = logical.getRightOperand() and inVoidContext(logical))
or
exists(ConditionalExpr cond | e = cond.getABranch() | inVoidContext(cond))
}
/**

View File

@@ -10,4 +10,5 @@
| tst.js:50:3:50:49 | new Syn ... o me?") | This expression has no effect. |
| tst.js:51:3:51:36 | new Err ... age(e)) | This expression has no effect. |
| tst.js:62:2:62:20 | o.trivialNonGetter1 | This expression has no effect. |
| tst.js:78:24:78:24 | o | This expression has no effect. |
| uselessfn.js:1:1:1:15 | (functi ... .");\\n}) | This expression has no effect. |

View File

@@ -73,5 +73,11 @@ function g() {
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
o.nonTrivialGetter2; // OK
(o: empty); // OK.
(o: empty); // OK
testSomeCondition() ? o : // NOT OK
doSomethingDangerous();
consume(testSomeCondition() ? o : // OK
doSomethingDangerous());
};