diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index bb819b59a53..ed776d07a1c 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -79,10 +79,13 @@ class AstNode extends TAstNode { * Gets the predicate that contains this AST node. */ pragma[noinline] - Predicate getEnclosingPredicate() { - not this instanceof Predicate and - toQL(result) = toQL(this).getParent+() - } + Predicate getEnclosingPredicate() { this = getANodeInPredicate(result) } +} + +private AstNode getANodeInPredicate(Predicate pred) { + result = pred.getAChild(_) + or + result = getANodeInPredicate(pred).getAChild(_) } /** A toplevel QL program, i.e. a file. */