Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Add type annotations" doesn't handle dynamic correctly #56730

Open
gspencergoog opened this issue Sep 13, 2024 · 2 comments
Open

"Add type annotations" doesn't handle dynamic correctly #56730

gspencergoog opened this issue Sep 13, 2024 · 2 comments
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@gspencergoog
Copy link
Contributor

In VSCode, when I use the code suggestion "Add type annotations" and the type includes dynamic, then it will insert <> instead of <dynamic>. I think this feature uses analyzer, which is why I filed this here.

For instance, if I have the following declaration:

final List<dynamic> data = [];

and I invoke "Add type annotation", it produces:

final List<dynamic> data = <>[];

instead of the expected:

final List<dynamic> data = <dynamic>[];

Dart version

  • Dart 3.6.0-175.0.dev (dev) (Fri Aug 23 09:07:06 2024 -0700) on "linux_x64"
  • on linux / Linux 6.9.10-1rodete4-amd64 Process tests sometimes cause timeout on Linux #1 SMP PREEMPT_DYNAMIC Debian 6.9.10-1rodete4 (2024-08-02)
  • locale is en_US.UTF-8
  • Dart VSCode extension: v3.96.0
@dart-github-bot
Copy link
Collaborator

Summary: The "Add type annotations" feature in VS Code incorrectly inserts <> instead of <dynamic> when the type includes dynamic, leading to invalid code. This issue likely stems from the analyzer's behavior.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Sep 13, 2024
@gspencergoog
Copy link
Contributor Author

Also, if the type is nested, it omits the type when it is explicitly dynamic:

final Map<String, List<dynamic>> data = {'string': []};

maps to:

final Map<String, List<dynamic>> data = <String, List>{'string': <>[]};

Instead of:

final Map<String, List<dynamic>> data = <String, List<dynamic>>{'string': <dynamic>[]};

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Sep 14, 2024
@srawlins srawlins added analyzer-quick-fix P2 A bug or feature request we're likely to work on labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants