Merge pull request #21254 from owen-mc/go/astnode-get-enclosing-block

Go: Add `AstNode.getEnclosingBlock()`
This commit is contained in:
Owen Mansel-Chan
2026-02-06 22:23:15 +00:00
committed by GitHub

View File

@@ -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.
*/