Skip to content

Commit a4ee152

Browse files
authored
Merge pull request #13512 from kaspersv/rc/3.10
QL language ref: explain implicit this receivers
2 parents 1f6fae8 + 8015c3c commit a4ee152

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/codeql/ql-language-reference/formulas.rst

+32
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ If the call resolves to a predicate without result, then the call is a formula.
164164
It is also possible to call a predicate with result. This kind of call is an
165165
expression in QL, instead of a formula. For more information, see ":ref:`calls-with-result`."
166166

167+
Member predicates only apply to members of a particular class and calls to
168+
member predicates have a receiver of a matching type. Syntactically, if a call
169+
contains a dot, then the expression before the dot specifies the receiver of
170+
the call. For instance, ``x`` is the receiver for the call ``x.isEven()``.
171+
172+
For calls to member predicates of the enclosing class on the member itself
173+
(i.e., the value of ``this``), the receiver may be omitted syntactically. In
174+
this case we say the call has an implicit this receiver. For instance, in the
175+
following example the ``isEven()`` call in ``isOdd()`` is a member predicate
176+
call with an implicit this receiver and the call is equivalent to
177+
``this.isEven()``:
178+
179+
.. code-block:: ql
180+
181+
class OneTwoThree extends int {
182+
OneTwoThree() { this = 1 or this = 2 or this = 3 }
183+
184+
predicate isEven() { this = 2 }
185+
186+
predicate isOdd() { not isEven() }
187+
}
188+
189+
Use of implicit this receivers can make it harder to spot predicates that introduce
190+
cartesian products by failing to relate the implicit ``this`` variable with
191+
other variables, which can negatively affect query performance. For more
192+
information on cartesian products, see ":ref:`Troubleshooting query performance
193+
<troubleshooting-query-performance>`".
194+
195+
It is possible to enable warnings about implicit this receivers for `CodeQL packs
196+
<https://docs.github.com/en/code-security/codeql-cli/codeql-cli-reference/about-codeql-packs#warnonimplicitthis>`__
197+
through the ``warnOnImplicitThis`` property.
198+
167199
.. _parenthesized-formulas:
168200

169201
Parenthesized formulas

0 commit comments

Comments
 (0)