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

type_annotate_public_apis reports missing type for static const #1121

Closed
chalin opened this issue Aug 9, 2018 · 1 comment · Fixed by #1541
Closed

type_annotate_public_apis reports missing type for static const #1121

chalin opened this issue Aug 9, 2018 · 1 comment · Fixed by #1541
Labels
false-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@chalin
Copy link
Contributor

chalin commented Aug 9, 2018

Consider the following class member declaration:

class Queue {
  static const initialCapacity = 16;
}

The type_annotate_public_apis lint causes this issue to be reported:

lint • Type annotate public APIs at lib/language_tour/classes/misc.dart:22:16 • type_annotate_public_apis

Being a static const, its type is fully determined at compile time from the initializer, so a type annotation would be redundant, and certainly should not be required -- as the lint message seems to suggest.

Of course, such a static const w/o an explicit type annotation can end up having type dynamic, which might not be desirable, but that is another issue addressed via the --no-implicit-dynamic flag IMHO.

cc @munificent @kwalrath @kevmoo

@pq
Copy link
Member

pq commented Apr 25, 2019

Looking at https://www.dartlang.org/guides/language/effective-dart/design#prefer-type-annotating-public-fields-and-top-level-variables-if-the-type-isnt-obvious, I'm pretty sure you're right and we should go ahead and do this for the "obvious" cases (and this one at least).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
3 participants