@@ -485,38 +485,41 @@ program, so it's helpful to extend a new type (namely ``TTaintType``)::
485
485
Type Unions
486
486
***********
487
487
488
- .. note :: The syntax for type unions is considered experimental and is subject to change.
489
- However, they appear in the `standard QL libraries <https://github.com/github/codeql> `.
490
- The following sections should help you understand those examples
491
-
492
- Type unions are user-defined types that are declared with the keyword ``class ``.
493
- The syntax resembles type aliases, but with two or more type expressions on the right-hand side.
494
-
495
- Type unions are used for creating restricted versions of existing algebraic datatypes, by explicitly
496
- selecting a subset of the branches of said datatype and binding them to a new type.
497
- In addition to this, type unions of database types are also supported.
498
-
499
- Using a type union to explicitly restrict the permitted branches from an algebraic datatype
500
- can resolve spurious recursion in predicates.
501
- For example, the following construction is legal::
502
-
503
- newtype T =
504
- T1(T t) { not exists(T2orT3 s | t = s) } or
505
- T2(int x) { x = 1 or x = 2 } or
506
- T3(int x) { x = 3 or x = 4 or x = 5 }
507
-
508
- class T2orT3 = T2 or T3;
509
-
510
- However, a similar implementation that restricts ``T `` in a class extension is not valid.
511
- The class ``T2orT3 `` triggers a type test for ``T ``, which results in an illegal recursion
512
- ``T2orT3->T->T1->¬T2orT2 `` due to the reliance of ``T1 `` on ``T2orT3 ``::
513
-
514
- class T2orT3 extends T {
515
- T2orT3() {
516
- this instanceof T2 or this instanceof T3
517
- }
518
- // ...
519
- }
488
+ .. note ::
489
+ 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
492
+
493
+ 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.
495
+
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.
499
+
500
+ Using a type union to explicitly restrict the permitted branches from an algebraic datatype
501
+ can resolve spurious recursion in predicates.
502
+ For example, the following construction is legal::
503
+
504
+ 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 }
508
+
509
+ class T2orT3 = T2 or T3;
510
+
511
+ However, a similar implementation that restricts ``T `` in a class extension is not valid.
512
+ 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 ``::
514
+
515
+ class T2orT3 extends T {
516
+ T2orT3() {
517
+ this instanceof T2 or this instanceof T3
518
+ }
519
+ // ...
520
+ }
521
+
522
+ Type unions are supported from release 2.2.0 of the CodeQL CLI.
520
523
521
524
.. _database-types :
522
525
0 commit comments