Skip to content

Lint for missing type info in formal parameter #57147

Open
@pq

Description

@pq

Discovered in the wild a number of cases like this:

typedef A(B);
typedef B(dynamic);

Both of them are essentially equivalent to dynamic->dynamic which is most likely not what the user has in mind. Instead, they likely mean:

typedef A(B _);
typedef B(dynamic _);

As Paul Berry points out it's a nasty user trap in the language, especially for people coming from a C/C++ background where using a single identifier as a formal parameter denotes the type of the formal parameter. A proposed lint:

whenever a single identifier is used to name a formal parameter, check the enclosing scope to see if
the name shadows a type. If it does, give a hint because the user probably meant the identifier to
denote the type of the formal parameter. We could even add a quick fix which adds "_" as the
parameter name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-requesttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions