CodeQL: Support multiple types for `instanceof`
- 主要语言
- CodeQL
- 星标
- 10.1k
- 派生
- 2.1k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 141
描述
Currently `instanceof` only supports a single type as right operand. This can make its usage quite verbose when multiple alternative type checks have to be performed. For example search in the CodeQL source with the following Regex (increasing or decreasing the number in `{3,}` to find longer or shorter chains):
```
(.+) instanceof [a-zA-Z]+([\s\n]+or[\s\n]+\1 instanceof [a-zA-Z]+){3,}
```
This finds for example:
- https://github.com/github/codeql/blob/3119885a9b21951aafac88e01c946b3e7cfbe163/java/ql/lib/semmle/code/java/ControlFlowGraph.qll#L441-L451
- https://github.com/github/codeql/blob/3119885a9b21951aafac88e01c946b3e7cfbe163/java/ql/lib/semmle/code/java/JDK.qll#L157-L161
Would it be possible to allow multiple types for the `instanceof` expression? The syntax could be similar to a set literal, also allowing a trailing comma (except that currently a set literal is defined as expression, so it would not be valid for types), for example:
```codeql
this instanceof [PrimitiveType, NullType, VoidType, BoxedType, TypeString]
```
贡献指南
评估
这个 Issue 还没有评估数据。