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

False positive: avoid_types_on_closure_parameters on closure assigned to a variable. #4633

Closed
hamsbrar opened this issue Jul 26, 2023 · 4 comments

Comments

@hamsbrar
Copy link

hamsbrar commented Jul 26, 2023

void main() {
  var _fn = (String name) => name.toUpperCase();
  //           ^ Unnecessary type annotation on a function expression parameter. Try removing the type annotation.
  _fn('a');

And if I remove the type hint:

void main() {
  var _fn = (name) => name.toUpperCase();
  //           ^ The type of name can't be inferred; a type must be explicitly provided.
> dart --version
Dart SDK version: 3.0.6 (stable) (Tue Jul 11 18:49:07 2023 +0000) on "linux_x64"

Actual example:

class GenerateUserRoleActionTemplateFor {
  static createPostWatchQuotaLifetime(bool self, TypePostWatch type) => _createPostWatchQuotaLifetime(self, type);
  // ...
}

// top-level
final _createPostWatchQuotaLifetime = (bool self, TypePostWatch type) =>
    //                                 ~~~~       ~~~~~~~~~~~~~
    __unlimitedCheck +
    '''
        \$userId = \$userModel->getId();

        \$countLifetime = ( new Query( TypeTable::POST_WATCH, true ) )
            ->${self ? 'where' : 'whereNot'}( TypeTablePostWatch::POST_USER_ID, \$userId )
            ->where( TypeTablePostWatch::WATCHER_USER_ID, \$userId )
            ->where( TypeTablePostWatch::TYPE, TypePostWatch::${TypedString.fromCamelCase(type.name).snakeCase.upperCase.toString()} )
            ->count();

        return CoreNumber::from( \$this->\$\$settingCamelCase  ) > \$countLifetime;
''';
@hamsbrar

This comment was marked as outdated.

@hamsbrar
Copy link
Author

Further investigation shows that it's because of using the lint avoid_types_on_closure_parameters and strict-inference in conjunction. Both VSCodium and VSCode shows the same warning with following analysis options:

analyzer:
  language:
    strict-inference: true

linter:
  rules:
    - avoid_types_on_closure_parameters

@hamsbrar hamsbrar reopened this Jul 26, 2023
@lrhn
Copy link
Member

lrhn commented Aug 1, 2023

Seems like a lint issue. Moving to linter repo.

@lrhn lrhn transferred this issue from dart-lang/sdk Aug 1, 2023
@srawlins srawlins changed the title False positive: Unnecessary type annotation on a function expression False positive: avoid_types_on_closure_parameters on closure assigned to a variable. Aug 1, 2023
@srawlins
Copy link
Member

srawlins commented Aug 1, 2023

Looks like a duplicate of #1099

@srawlins srawlins closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants