mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
add support for rest types elements in the middle of a tuple
This commit is contained in:
@@ -2149,18 +2149,23 @@ class TupleType extends ArrayType, @tuple_type {
|
||||
int getMinimumLength() { tuple_type_min_length(this, result) }
|
||||
|
||||
/**
|
||||
* Holds if this tuple type ends with a rest element, such as `[number, ...string[]]`.
|
||||
* Gets the index of the rest element.
|
||||
* E.g. for a type `[number, ...string[]]` the result is 1,
|
||||
* or for a type `[...number[], string]` the result is 0.
|
||||
*/
|
||||
predicate hasRestElement() { tuple_type_rest(this) }
|
||||
int getRestElementIndex() { tuple_type_rest_index(this, result) }
|
||||
|
||||
/**
|
||||
* Holds if this tuple type has a rest element, such as `[number, ...string[]]` or `[...number[], string]`.
|
||||
*/
|
||||
predicate hasRestElement() { exists(getRestElementIndex()) }
|
||||
|
||||
/**
|
||||
* Gets the type of the rest element, if there is one.
|
||||
*
|
||||
* For example, the rest element of `[number, ...string[]]` is `string`.
|
||||
*/
|
||||
Type getRestElementType() {
|
||||
hasRestElement() and result = getElementType(getNumElementType() - 1)
|
||||
}
|
||||
Type getRestElementType() { result = getElementType(getRestElementIndex()) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -799,8 +799,9 @@ tuple_type_min_length(
|
||||
int minLength: int ref
|
||||
);
|
||||
|
||||
tuple_type_rest(
|
||||
unique int typ: @type ref
|
||||
tuple_type_rest_index(
|
||||
unique int typ: @type ref,
|
||||
int index: int ref
|
||||
);
|
||||
|
||||
// comments
|
||||
|
||||
Reference in New Issue
Block a user