|
4 | 4 | newtype TControlFlowElement = |
5 | 5 | TAstElement(AstNode n) or |
6 | 6 | TFuncDeclElement(Function func) { func.hasBody() } or |
7 | | - TClosureElement(ExplicitClosureExpr clos) or |
| 7 | + TClosureElement(ClosureExpr clos) { isNormalAutoClosureOrExplicitClosure(clos) } or |
8 | 8 | TPropertyGetterElement(Decl accessor, Expr ref) { isPropertyGetterElement(accessor, ref) } or |
9 | 9 | TPropertySetterElement(Accessor accessor, AssignExpr assign) { |
10 | 10 | isPropertySetterElement(accessor, assign) |
@@ -41,6 +41,15 @@ predicate isPropertyGetterElement(PropertyGetterElement pge, Accessor accessor, |
41 | 41 | pge = TPropertyGetterElement(accessor, ref) |
42 | 42 | } |
43 | 43 |
|
| 44 | +predicate isNormalAutoClosureOrExplicitClosure(ClosureExpr clos) { |
| 45 | + // short-circuiting operators have a `BinaryExpr` as the parent of the `AutoClosureExpr`, |
| 46 | + // so we exclude them by checking for a `CallExpr`. |
| 47 | + clos instanceof AutoClosureExpr and |
| 48 | + exists(CallExpr call | call.getAnArgument().getExpr() = clos) |
| 49 | + or |
| 50 | + clos instanceof ExplicitClosureExpr |
| 51 | +} |
| 52 | + |
44 | 53 | private predicate hasDirectToImplementationSemantics(Expr e) { |
45 | 54 | e.(MemberRefExpr).hasDirectToImplementationSemantics() |
46 | 55 | or |
@@ -194,14 +203,18 @@ class KeyPathElement extends ControlFlowElement, TKeyPathElement { |
194 | 203 | override string toString() { result = expr.toString() } |
195 | 204 | } |
196 | 205 |
|
| 206 | +/** |
| 207 | + * A control flow element representing a closure in its role as a control flow |
| 208 | + * scope. |
| 209 | + */ |
197 | 210 | class ClosureElement extends ControlFlowElement, TClosureElement { |
198 | | - ExplicitClosureExpr expr; |
| 211 | + ClosureExpr expr; |
199 | 212 |
|
200 | 213 | ClosureElement() { this = TClosureElement(expr) } |
201 | 214 |
|
202 | 215 | override Location getLocation() { result = expr.getLocation() } |
203 | 216 |
|
204 | | - ExplicitClosureExpr getAst() { result = expr } |
| 217 | + ClosureExpr getAst() { result = expr } |
205 | 218 |
|
206 | 219 | override string toString() { result = expr.toString() } |
207 | 220 | } |
|
0 commit comments