Skip to content

prefer_contains does not catch type parameters bound to Iterable (or promoted to) #58406

Open
@srawlins

Description

@srawlins

Describe the issue

prefer_contains does not catch type parameters bound to Iterable (or promoted to a bound of Iterable). For example:

To Reproduce

bool typeVariableBoundToList<T extends List<int>>(T list) =>
    list.indexOf(1) < 0; // LINT

bool typeVariablePromotedToList<T>(T list) =>
    list is List<int> && list.indexOf(1) < 0; // LINT

Expected behavior

Each of these should be reported.

Additional context

The recent typeForInterfaceCheck extension method on DartType should help. only_throw_errors needed a similar fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.linter-false-negativeIssues related to lint rules that fail to report a problem.linter-set-recommendedtype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions