File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
test/query-tests/Expressions/MissingAwait Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -13,20 +13,20 @@ import javascript
1313/**
1414 * Holds if `call` is a call to an `async` function.
1515 */
16- predicate isAsyncCall ( DataFlow:: CallNode call ) {
16+ predicate isAsyncCall ( DataFlow:: CallNode call , boolean nullable ) {
1717 // If a callee is known, and all known callees are async, assume all
1818 // possible callees are async.
19- forex ( Function callee | call .getACallee ( ) = callee | callee .isAsync ( ) )
19+ forex ( Function callee | call .getACallee ( ) = callee | callee .isAsync ( ) ) and
20+ if call .asExpr ( ) instanceof OptionalUse then nullable = true else nullable = false
2021}
2122
2223/**
2324 * Holds if `node` is always a promise.
2425 */
2526predicate isPromise ( DataFlow:: SourceNode node , boolean nullable ) {
26- isAsyncCall ( node ) and
27- nullable = false
27+ isAsyncCall ( node , nullable )
2828 or
29- not isAsyncCall ( node ) and
29+ not isAsyncCall ( node , _ ) and
3030 node .asExpr ( ) .getType ( ) instanceof PromiseType and
3131 nullable = true
3232}
Original file line number Diff line number Diff line change 77| tst.js:22:15:22:19 | thing | Missing await. The value 'thing' is always a promise. |
88| tst.js:25:13:25:17 | thing | Missing await. The value 'thing' is always a promise. |
99| tst.js:48:12:48:16 | thing | Missing await. The value 'thing' is always a promise. |
10+ | tst.js:71:16:71:25 | getThing() | Missing await. The call to 'getThing' always returns a promise. |
Original file line number Diff line number Diff line change @@ -65,3 +65,11 @@ function useThingPossiblySync(b) {
6565function useThingInVoid ( ) {
6666 void getThing ( ) ; // OK
6767}
68+
69+ function useThing ( ) {
70+ if ( random ( ) ) {
71+ return getThing ( ) ?? null ; // NOT OK
72+ } else {
73+ return getThing ?. ( ) ?? null ; // OK
74+ }
75+ }
You can’t perform that action at this time.
0 commit comments