diff --git a/ql/src/codeql_ruby/ast/Call.qll b/ql/src/codeql_ruby/ast/Call.qll index b38b2b37263..366aab182a1 100644 --- a/ql/src/codeql_ruby/ast/Call.qll +++ b/ql/src/codeql_ruby/ast/Call.qll @@ -85,6 +85,21 @@ class MethodCall extends Call, TMethodCall { */ Expr getReceiver() { none() } + /** + * Holds if the receiver is `self` or there is no receiver, which has the same + * meaning as an explict `self`. For example: + * + * ```rb + * self.foo + * foo + * ``` + */ + predicate receiverIsSelf() { + this.getReceiver() instanceof Self + or + not exists(this.getReceiver()) + } + /** * Gets the name of the method being called. For example, in: * diff --git a/ql/src/codeql_ruby/ast/Method.qll b/ql/src/codeql_ruby/ast/Method.qll index 04eeaff9a1f..dffabffa649 100644 --- a/ql/src/codeql_ruby/ast/Method.qll +++ b/ql/src/codeql_ruby/ast/Method.qll @@ -8,13 +8,13 @@ private import internal.TreeSitter * A representation of a method. */ class Method extends TMethod { - /** Get a declaration of this module, if any. */ + /** Gets a declaration of this module, if any. */ MethodBase getADeclaration() { result.getMethod() = this } - /** Get the name of this method */ + /** Gets the name of this method */ string getName() { this = TInstanceMethod(_, result) } - /** Get the module in which this method is defined */ + /** Gets the module in which this method is defined */ Module getModule() { this = TInstanceMethod(result, _) } /** Gets a textual representation of this method. */ diff --git a/ql/src/codeql_ruby/ast/Module.qll b/ql/src/codeql_ruby/ast/Module.qll index 6e90a9f87db..ae46b46d0c2 100644 --- a/ql/src/codeql_ruby/ast/Module.qll +++ b/ql/src/codeql_ruby/ast/Module.qll @@ -8,22 +8,22 @@ private import internal.TreeSitter * A representation of a run-time `module` or `class` value. */ class Module extends TModule { - /** Get a declaration of this module, if any. */ + /** Gets a declaration of this module, if any. */ ModuleBase getADeclaration() { result.getModule() = this } - /** Get the super class of this module, if any. */ + /** Gets the super class of this module, if any. */ Module getSuperClass() { result = getSuperClass(this) } - /** Get a method defined in this module by name. */ + /** Gets a method defined in this module by name. */ Method getMethod(string name) { result.getName() = name and result.getModule() = this } /** Look up a method in this module's ancestor chain. */ Method lookupMethod(string name) { result = lookupMethod(this, name) } - /** Get a `prepend`ed module. */ + /** Gets a `prepend`ed module. */ Module getAPrependedModule() { result = getAPrependedModule(this) } - /** Get an `include`d module. */ + /** Gets an `include`d module. */ Module getAnIncludedModule() { result = getAnIncludedModule(this) } /** Gets a textual representation of this module. */ diff --git a/ql/src/codeql_ruby/ast/internal/Module.qll b/ql/src/codeql_ruby/ast/internal/Module.qll index 01a77f583d0..554516f3c2f 100644 --- a/ql/src/codeql_ruby/ast/internal/Module.qll +++ b/ql/src/codeql_ruby/ast/internal/Module.qll @@ -67,11 +67,7 @@ private module Cached { m = resolveScopeExpr(c.getReceiver()) or m = enclosingModule(c).getModule() and - ( - c.getReceiver() instanceof Self - or - not exists(c.getReceiver()) - ) + c.receiverIsSelf() ) and result = resolveScopeExpr(c.getAnArgument()) ) @@ -85,11 +81,7 @@ private module Cached { m = resolveScopeExpr(c.getReceiver()) or m = enclosingModule(c).getModule() and - ( - c.getReceiver() instanceof Self - or - not exists(c.getReceiver()) - ) + c.receiverIsSelf() ) and result = resolveScopeExpr(c.getAnArgument()) )