github / github/codeql

CodeQL: Support multiple types for `instanceof`

Đang mở
#8,662 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
CLI
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.