dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
629 stars 170 forks source link

`always_specify_types` falsely positives alias types of classes with type generics. #2671

Open Michael35699 opened 3 years ago

Michael35699 commented 3 years ago

Describe the issue A clear and concise description of what the issue is.

typedef ZTable = HashMap<String, String>;

void main() {
  ZTable table = ZTable(); // Specify type annotations.
}

I believe this is unexpected behavior, since the types are already declared.

To Reproduce

Given example above

Expected behavior

There would be no lint error.

Additional context

N/A

yjbanov commented 3 years ago

This also happens in other contexts:

typedef Json = Map<String, dynamic>;

extension JsonMethod on Json {
//                      ^^^^ here
  Json dict(String propertyName) {
//^^^^ here
    return this[propertyName] as Json;
//                               ^^^^ here
  }
}
asashour commented 3 years ago

I am not able to reproduce on master, but I am able to reproduce with Dart SDK version: 2.14.0-321.0.dev

Could it be that the linter is somehow different from the one in the SDK, that discrepancy is also shown in https://github.com/dart-lang/linter/issues/2597

With master, adding the far below at the end of always_specify_types.dart test case gives successful result, although putting a wrong LINT gives an error

EXPERIMENT_NOT_ENABLED: This requires the 'nonfunction-type-aliases' language feature to be enabled.

Test case:

typedef ZTable = HashMap<String, String>;

void m() {
  ZTable table = ZTable(); // OK
}

typedef Json = Map<String, dynamic>;

extension JsonMethod on Json {
  Json dict(String propertyName) {
    return this[propertyName] as Json;
  }
}
bwilkerson commented 3 years ago

Which master? On the master branch of the SDK that feature is marked as being enabled by default, so you shouldn't see the EXPERIMENT_NOT_ENABLED diagnostic.

asashour commented 3 years ago

I meant linter master, at the moment I didn't go into the SDK and see how to use a modified linter, this would be the next step.

At the moment, I hope someone points to a reproducible issue in linter master, so it can be modified and tested there.