diff --git a/ql/src/codeql_ruby/ast/Method.qll b/ql/src/codeql_ruby/ast/Method.qll index 7c205f174ab..648392b28f0 100644 --- a/ql/src/codeql_ruby/ast/Method.qll +++ b/ql/src/codeql_ruby/ast/Method.qll @@ -4,7 +4,7 @@ private import internal.AST private import internal.TreeSitter /** A callable. */ -class Callable extends Expr, TCallable { +class Callable extends Expr, Scope, TCallable { /** Gets the number of parameters of this callable. */ final int getNumberOfParameters() { result = count(this.getAParameter()) } diff --git a/ql/src/codeql_ruby/ast/Module.qll b/ql/src/codeql_ruby/ast/Module.qll index 6279a7e8a15..07a36091324 100644 --- a/ql/src/codeql_ruby/ast/Module.qll +++ b/ql/src/codeql_ruby/ast/Module.qll @@ -6,7 +6,7 @@ private import internal.TreeSitter /** * The base class for classes, singleton classes, and modules. */ -class ModuleBase extends BodyStmt, TModuleBase { +class ModuleBase extends BodyStmt, Scope, TModuleBase { /** Gets a method defined in this module/class. */ MethodBase getAMethod() { result = this.getAStmt() } diff --git a/ql/src/codeql_ruby/ast/Scope.qll b/ql/src/codeql_ruby/ast/Scope.qll index 36b23e880e5..2f4b941a56e 100644 --- a/ql/src/codeql_ruby/ast/Scope.qll +++ b/ql/src/codeql_ruby/ast/Scope.qll @@ -17,6 +17,9 @@ class Scope extends AstNode, TScopeType { /** Gets the scope in which this scope is nested, if any. */ Scope getOuterScope() { toGenerated(result) = range.getOuterScope() } + /** Gets the scope in which this scope is nested, if any. */ + AstNode getADescendant() { range = scopeOf(toGenerated(result)) } + /** Gets a variable that is declared in this scope. */ final Variable getAVariable() { result.getDeclaringScope() = this }