Skip to content

Commit 2ec5e72

Browse files
authored
Merge pull request github#13633 from github/ginsbach/SpecifyExtendsFinal
document final extensions in the language specification
2 parents b651c02 + cff8861 commit 2ec5e72

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -959,13 +959,18 @@ The types specified after the ``extends`` keyword are the *base types* of the cl
959959

960960
The types specified after the ``instanceof`` keyword are the *instanceof types* of the class.
961961

962-
A class type is said to *inherit* from the base types. In addition, inheritance is transitive: If a type ``A`` inherits from a type ``B``, and ``B`` inherits from a type ``C``, then ``A`` inherits from ``C``.
962+
A class type is said to *final inherit* from base types that are final or referenced through final aliases, and a class type is said to *inherit* from its other base types. In addition, inheritance is transitive:
963+
964+
- If a type ``A`` inherits from a type ``B``, and ``B`` inherits from a type ``C``, then ``A`` inherits from ``C``.
965+
- If a type ``A`` final inherits from a type ``B``, and ``B`` inherits from a type ``C``, then ``A`` final inherits from ``C``.
966+
- If a type ``A`` inherits from a type ``B``, and ``B`` final inherits from a type ``C``, then ``A`` final inherits from ``C``.
967+
- If a type ``A`` final inherits from a type ``B``, and ``B`` final inherits from a type ``C``, then ``A`` final inherits from ``C``.
963968

964969
A class adds a mapping from the class name to the class declaration to the current module's declared type environment.
965970

966971
A valid class can be annotated with ``abstract``, ``final``, ``library``, and ``private``. Any other annotation renders the class invalid.
967972

968-
A valid class may not inherit from a final class, from itself, or from more than one primitive type.
973+
A valid class may not inherit from itself, or from more than one primitive type. The set of types that a valid class inherits from must be disjoint from the set of types that it final inherits from.
969974

970975
A valid class must have at least one base type or instanceof type.
971976

@@ -975,9 +980,10 @@ Class dependencies
975980
The program is invalid if there is a cycle of class dependencies.
976981

977982
The following are class dependencies:
983+
978984
- ``C`` depends on ``C.C``
979985
- ``C.C`` depends on ``C.extends``
980-
- If ``C`` is abstract then it depends on all classes ``D`` such that ``C`` is a base type of ``D``.
986+
- If ``C`` is abstract then it depends on all classes ``D`` such that ``C`` is a base type of ``D`` and ``D`` inherits from ``C``.
981987
- ``C.extends`` depends on ``D.D`` for each base type ``D`` of ``C``.
982988
- ``C.extends`` depends on ``D`` for each instanceof type ``D`` of ``C``.
983989

@@ -1029,7 +1035,9 @@ A valid member predicate can be annotated with ``abstract``, ``cached``, ``final
10291035

10301036
If a type is provided before the name of the member predicate, then that type is the *result type* of the predicate. Otherwise, the predicate has no result type. The types of the variables in the ``var_decls`` are called the predicate's *argument types*.
10311037

1032-
A member predicate ``p`` with enclosing class ``C`` *overrides* a member predicate ``p'`` with enclosing class ``D`` when ``C`` inherits from ``D``, ``p'`` is visible in ``C``, and both ``p`` and ``p'`` have the same name and the same arity. An overriding predicate must have the same sequence of argument types as any predicates which it overrides, otherwise the program is invalid.
1038+
A member predicate ``p`` with enclosing class ``C`` *overrides* a member predicate ``p'`` with enclosing class ``D`` when ``p`` is annotated ``overrride``, ``C`` inherits from ``D``, ``p'`` is visible in ``C``, ``p'`` is not final, and both ``p`` and ``p'`` have the same name and the same arity. An overriding predicate must have the same sequence of argument types as any predicates which it overrides, otherwise the program is invalid.
1039+
1040+
A member predicate ``p`` with enclosing class ``C`` *shadows* a member predicate ``p'`` with enclosing class ``D`` when ``C`` final inherits from ``D``, ``p'`` is visible in ``C``, and both ``p`` and ``p'`` have the same name and the same arity. Additionally, a member predicate ``p`` with enclosing class ``C`` *shadows* a member predicate ``p'`` with enclosing class ``D`` when ``C`` inherits from ``D``, ``p'`` is visible in ``C``, ``p'`` is final, and both ``p`` and ``p'`` have the same name and the same arity.
10331041

10341042
Member predicates have one or more *root definitions*. If a member predicate overrides no other member predicate, then it is its own root definition. Otherwise, its root definitions are those of any member predicate that it overrides.
10351043

@@ -1043,7 +1051,9 @@ A class may not inherit from a class with an abstract member predicate unless it
10431051

10441052
A valid class must include a non-private predicate named ``toString`` with no arguments and a result type of ``string``, or it must inherit from a class that does.
10451053

1046-
A valid class may not inherit from two different classes that include a predicate with the same name and number of arguments, unless either one of the predicates overrides the other, or the class defines a predicate that overrides both of them.
1054+
A valid class may not inherit from two different classes that include a predicate with the same name and number of arguments, unless either one of the predicates overrides or shadows the other, or the class defines a predicate that overrides or shadows both of them.
1055+
1056+
A valid class may not final inherit from two different classes that include a predicate with the same name and number of arguments, unless either one of the predicates overrides or shadows the other, or the class defines a predicate that shadows both of them.
10471057

10481058
The typing environment for a member predicate or character is the same as if it were a non-member predicate, except that it additionally maps ``this`` to a type and also maps any fields on a class to a type. If the member is a character, then the typing environment maps ``this`` to the class domain type of the class. Otherwise, it maps ``this`` to the class type of the class itself.
10491059
The typing environment also maps any field to the type of the field.
@@ -1053,9 +1063,13 @@ Fields
10531063

10541064
A field declaration introduces a mapping from the field name to the field declaration in the class's declared field environment.
10551065

1056-
A field ``f`` with enclosing class ``C`` *overrides* a field ``f'`` with enclosing class ``D`` when ``f`` is annotated ``override``, ``C`` inherits from ``D``, ``p'`` is visible in ``C``, and both ``p`` and ``p'`` have the same name.
1066+
A field ``f`` with enclosing class ``C`` *overrides* a field ``f'`` with enclosing class ``D`` when ``f`` is annotated ``override``, ``C`` inherits from ``D``, ``p'`` is visible in ``C``, ``p'`` is not final, and both ``p`` and ``p'`` have the same name.
1067+
1068+
A field ``f`` with enclosing class ``C`` *shadows* a field ``f'`` with enclosing class ``D`` when ``C`` final inherits from ``D``, ``p'`` is visible in ``C``, and both ``p`` and ``p'`` have the same name. Additionally, a field ``f`` with enclosing class ``C`` *shadows* a field ``f'`` with enclosing class ``D`` when ``C`` inherits from ``D``, ``p'`` is visible in ``C``, ``p'`` is final, and both ``p`` and ``p'`` have the same name.
1069+
1070+
A valid class may not inherit from two different classes that include a field with the same name, unless either one of the fields overrides or shadows the other, or the class defines a field that overrides or shadows both of them.
10571071

1058-
A valid class may not inherit from two different classes that include a field with the same name, unless either one of the fields overrides the other, or the class defines a field that overrides both of them.
1072+
A valid class may not final inherit from two different classes that include a field with the same name, unless either one of the fields overrides or shadows the other, or the class defines a field that shadows both of them.
10591073

10601074
A valid field must override another field if it is annotated ``override``.
10611075

@@ -1349,9 +1363,10 @@ If the call includes a closure, then all declared predicate arguments, the enclo
13491363

13501364
A call to a member predicate may be a *direct* call:
13511365
- If the receiver is not a super expression it is not direct.
1352-
- If the receiver is ``A.super`` and ``A`` is an instanceof type and not a base type then it is not direct.
1353-
- If the receiver is ``A.super`` and ``A`` is a base type type and not an instanceof type then it is direct.
1354-
- If the receiver is ``A.super`` and ``A`` is a base type and an instanceof type then the call is not valid.
1366+
- If the receiver is ``A.super`` and ``A`` is an instanceof type and not a base type that is inherited from then it is not direct.
1367+
- If the receiver is ``A.super`` and ``A`` is a base type that is final inherited from then it is not direct.
1368+
- If the receiver is ``A.super`` and ``A`` is a base type that is inherited from and not an instanceof type then it is direct.
1369+
- If the receiver is ``A.super`` and ``A`` is a base type that is inherited from and an instanceof type then the call is not valid.
13551370
- If the receiver is ``super`` and the member predicate is in the exported member predicate environment of an instanceof type and not in the exported member predicate environment of a base type then it isn't direct.
13561371
- If the receiver is ``super`` and the member predicate is in the exported member predicate environment of a base type and not in the exported member predicate environment of an instanceof type then it is direct.
13571372
- If the receiver is ``super`` and the member predicate is in the exported member predicate environment of a base type and in the exported member predicate environment of an instanceof type then the call is not valid.
@@ -2123,7 +2138,7 @@ Predicates, and types can *depend* and *strictly depend* on each other. Such dep
21232138

21242139
- For each class ``C`` with a characteristic predicate, ``C.C`` depends on the characteristic predicate.
21252140

2126-
- For each abstract class ``A`` in the program, for each type ``C`` that has ``A`` as a base type, ``A.class`` depends on ``C.class``.
2141+
- For each abstract class ``A`` in the program, for each type ``C`` that inherits from ``A`` and has ``A`` as a base type, ``A.class`` depends on ``C.class``.
21272142

21282143
- A predicate with a higher-order body may strictly depend or depend on each predicate reference within the body. The exact dependencies are left unspecified.
21292144

@@ -2175,7 +2190,7 @@ Each layer of the stratification is *populated* in order. To populate a layer, e
21752190

21762191
- To populate the type ``C.class`` for an abstract class type ``C``, identify each named tuple that has the following properties:
21772192
- It is a member of ``C.C``.
2178-
- For each class ``D`` that has ``C`` as a base type then there is a named tuple with variables from the public fields of ``C`` and ``this`` that the given tuple and a tuple in ``D.class`` both extend.
2193+
- For each class ``D`` that inherits from ``C`` and has ``C`` as a base type then there is a named tuple with variables from the public fields of ``C`` and ``this`` that the given tuple and a tuple in ``D.class`` both extend.
21792194

21802195

21812196
Query evaluation

0 commit comments

Comments
 (0)