From 8aa1bff9a5ae7c8def20b98a22445a8e2f452be0 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Sun, 1 Feb 2026 22:59:19 +0000 Subject: [PATCH] Add `AstNode.getEnclosingBlock()` --- go/ql/lib/semmle/go/AST.qll | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go/ql/lib/semmle/go/AST.qll b/go/ql/lib/semmle/go/AST.qll index c5e388ba000f..6a840f81cbbe 100644 --- a/go/ql/lib/semmle/go/AST.qll +++ b/go/ql/lib/semmle/go/AST.qll @@ -84,6 +84,16 @@ class AstNode extends @node, Locatable { pragma[nomagic] FuncDef getEnclosingFunction() { result = this.getParent().parentInSameFunction*() } + /** Gets the innermost block statement to which this AST node belongs, if any. */ + BlockStmt getEnclosingBlock() { + exists(AstNode p | p = this.getParent() | + result = p + or + not p instanceof BlockStmt and + result = p.getEnclosingBlock() + ) + } + /** * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. */