Skip to content

Commit 748d01f

Browse files
authored
Merge pull request #1 from shati-patel/typeunions-edits
Editorial suggestions for "type unions"
2 parents 460b64c + 6c9c803 commit 748d01f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

docs/language/ql-handbook/aliases.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ of ``OldVersion``, you could deprecate the name ``OldVersion`` as follows::
4242
That way both names resolve to the same module, but if you use the name ``OldVersion``,
4343
a deprecation warning is displayed.
4444

45+
.. _type-aliases:
46+
4547
Type aliases
4648
============
4749

docs/language/ql-handbook/types.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,35 +482,35 @@ program, so it's helpful to extend a new type (namely ``TTaintType``)::
482482
483483
.. _type-unions:
484484

485-
Type Unions
485+
Type unions
486486
***********
487487

488488
.. note::
489489
The syntax for type unions is considered experimental and is subject to change.
490-
However, they appear in the `standard QL libraries <https://github.com/github/codeql>`.
491-
The following sections should help you understand those examples
490+
However, type unions appear in the `standard QL libraries <https://github.com/github/codeql>`__.
491+
The following sections should help you understand those examples.
492492

493493
Type unions are user-defined types that are declared with the keyword ``class``.
494-
The syntax resembles type aliases, but with two or more type expressions on the right-hand side.
494+
The syntax resembles :ref:`type aliases <type-aliases>`, but with two or more type expressions on the right-hand side.
495495

496-
Type unions are used for creating restricted versions of existing algebraic datatypes, by explicitly
497-
selecting a subset of the branches of said datatype and binding them to a new type.
498-
In addition to this, type unions of database types are also supported.
496+
Type unions are used for creating restricted versions of an existing :ref:`algebraic datatype <algebraic-datatypes>`, by explicitly
497+
selecting a subset of the branches of that datatype and binding them to a new type.
498+
Type unions of :ref:`database types <database-types>` are also supported.
499499

500-
Using a type union to explicitly restrict the permitted branches from an algebraic datatype
501-
can resolve spurious recursion in predicates.
500+
You can use a type union to explicitly restrict the permitted branches from an algebraic datatype
501+
and resolve spurious :ref:`recursion <recursion>` in predicates.
502502
For example, the following construction is legal::
503503

504504
newtype T =
505-
T1(T t) { not exists(T2orT3 s | t = s) } or
506-
T2(int x) { x = 1 or x = 2 } or
507-
T3(int x) { x = 3 or x = 4 or x = 5 }
505+
T1(T t) { not exists(T2orT3 s | t = s) } or
506+
T2(int x) { x = 1 or x = 2 } or
507+
T3(int x) { x = 3 or x = 4 or x = 5 }
508508

509509
class T2orT3 = T2 or T3;
510510

511511
However, a similar implementation that restricts ``T`` in a class extension is not valid.
512512
The class ``T2orT3`` triggers a type test for ``T``, which results in an illegal recursion
513-
``T2orT3->T->T1->¬T2orT2`` due to the reliance of ``T1`` on ``T2orT3``::
513+
``T2orT3 -> T -> T1 -> ¬T2orT3`` since ``T1`` relies on ``T2orT3``::
514514

515515
class T2orT3 extends T {
516516
T2orT3() {

0 commit comments

Comments
 (0)