Skip to content

CodeQL: Support multiple types for instanceof #8662

Open
@Marcono1234

Description

@Marcono1234

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:

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:

this instanceof [PrimitiveType, NullType, VoidType, BoxedType, TypeString]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions