github / github/codeql

CodeQL: Support multiple types for `instanceof`

Aperta
#8,662 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
CLI
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

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]
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.