Skip to content

Commit ad4715f

Browse files
authored
Merge pull request #1908 from shati-semmle/ql-hb/fixes
QL handbook: Add examples and fix typos
2 parents 2806a52 + cfa51a0 commit ad4715f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

docs/language/ql-handbook/predicates.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ multiple binding set annotations, for example::
262262
x + 1 = y
263263
}
264264

265+
from int x, int y
266+
where y = 42 and plusOne(x, y)
267+
select x, y
268+
265269
Multiple binding sets specified this way are independent of each other. The above example means:
266270
- If ``x`` is bound, then ``x`` and ``y`` are bound.
267271
- If ``y`` is bound, then ``x`` and ``y`` are bound.

docs/language/ql-handbook/queries.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ For example::
8383
result = x * y
8484
}
8585

86-
This predicates returns the following results:
86+
This predicate returns the following results:
8787

8888
+---+---+--------+
8989
| x | y | result |
@@ -96,8 +96,14 @@ This predicates returns the following results:
9696
+---+---+--------+
9797

9898
A benefit of writing a query predicate instead of a select clause is that you can call the
99-
predicate in other parts of the code too. In contrast, the select clause is like an anonymous
100-
predicate, so you can't call it later.
99+
predicate in other parts of the code too. For example, you can call ``getProduct`` inside
100+
the body of a :ref:`class <classes>`::
101+
102+
class MultipleOfThree extends int {
103+
MultipleOfThree() { this = getProduct(_, _) }
104+
}
105+
106+
In contrast, the select clause is like an anonymous predicate, so you can't call it later.
101107

102108
It can also be helpful to add a ``query`` annotation to a predicate while you debug code. That
103109
way you can explicitly see the set of tuples that the predicate evaluates to.

docs/language/ql-handbook/types.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ base types.
106106

107107
A class can extend multiple types. See :ref:`multiple-inheritance` below.
108108

109-
To be a valid, a class:
109+
To be valid, a class:
110110
- Must not extend itself.
111111
- Must not extend a :ref:`final` class.
112112
- Must not extend types that are incompatible. (See :ref:`type-compatibility`.)
@@ -147,7 +147,11 @@ predicate from the :ref:`above <defining-class>` class::
147147

148148
1.(OneTwoThree).getAString()
149149

150-
This call returns the results ``"One, two or three: 1"``.
150+
This call returns the result ``"One, two or three: 1"``.
151+
152+
The expression ``(OneTwoThree)`` is a :ref:`cast <casts>`. It ensures that ``1`` has type
153+
``OneTwoThree`` instead of just ``int``. Therefore, it has access to the member predicate
154+
``getAString()``.
151155

152156
Member predicates are especially useful because you can chain them together. For example, you
153157
can use ``toUpperCase()``, a built-in function defined for ``string``::

0 commit comments

Comments
 (0)