Skip to content

Request for lint: unnecessary_dynamic #58082

Open
@davidmorgan

Description

@davidmorgan

How about a lint that fires when you write dynamic for a parameter type but Object would have worked?

e.g.

void foo(dynamic bar) {
  if (bar is String) {
    ...
  } else if (bar is int) {
    ...
  } else throw UnsupportedError();
}

I see this pretty frequently and I think it hides a misunderstanding about what dynamic is useful for, i.e. for the rare cases when you want to turn off static checking and always do dynamic dispatch.

Happy to take a shot at implementing this if you think it makes sense, particularly if you can give hints about how to figure out whether dynamic dispatch was used :)

Thanks!

Activity

bwilkerson

bwilkerson commented on Dec 11, 2019

@bwilkerson
Member

@leafpetersen @srawlins
I know that we were, at one point, looking to define a coherent set of options related to uses of dynamic, but I don't know whether this would have been covered or what the current status of that work is. Is that still planned?

Should something like this be implemented as a lint, or would it be covered by the mechanisms above?

added
P3A lower priority bug or feature request
on Nov 20, 2024
added
area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
and removed on Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-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

        Participants

        @pq@devoncarew@davidmorgan@bwilkerson

        Issue actions

          Request for lint: unnecessary_dynamic · Issue #58082 · dart-lang/sdk