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

Suggestion: add @optionalTypeArgs to MapEntry #55709

Open
nate-thegrate opened this issue May 13, 2024 · 2 comments
Open

Suggestion: add @optionalTypeArgs to MapEntry #55709

nate-thegrate opened this issue May 13, 2024 · 2 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package analyzer-pkg-meta Issues related to package:meta 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

Comments

@nate-thegrate
Copy link

nate-thegrate commented May 13, 2024

Pattern-matching with MapEntry is very satisfying, but when always_specify_types is on, it's kinda awful.

final List<String> list = <String>[
  for (final MapEntry<KeyClass, ValueClassWithAVeryLongName>(:KeyClass key, :ValueClassWithAVeryLongName value) in map.entries)
    '$key, $value',
];

I'd much prefer not needing to add the type parameters here:

final List<String> list = <String>[
  for (final MapEntry(:KeyClass key, :ValueClassWithAVeryLongName value) in map.entries)
    '$key, $value',
];
@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label May 14, 2024
@lrhn
Copy link
Member

lrhn commented May 14, 2024

I think the lint is probably working as intended.

Requiring a type annotation for var x = 10;, where the inferred type is obvious, means that the lint really intends all types to be written, even if they are inferred.

I don't know if it's the same lint that requires the the type parameters to MapEntry. I'd have assumed that

   for (final MapEntry(:KeyClass key, :ValueClassWithAVeryLongName value)  ...

would be enough, since this lint is about the variable declarations. (And MapEntry is not a raw type here, so should not be affected by strict_raw_types.)

@nate-thegrate
Copy link
Author

nate-thegrate commented May 14, 2024

always_specify_types

It looks like the always_specify_type lint kicks in when you don't add the MapEntry type parameters. (I'll update the original comment for clarity.)

@scheglov scheglov added analyzer-linter Issues with the analyzer's support for the linter package P2 A bug or feature request we're likely to work on analyzer-pkg-meta Issues related to package:meta labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package analyzer-pkg-meta Issues related to package:meta 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
Projects
None yet
Development

No branches or pull requests

3 participants