-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Forked from an internal thread.
The strong-mode: true flag to static analysis currently has an optional flag, no_implicit_dynamic, which forces inference of dynamic, to be, well, not implicit 😏. On the other hand, it and no_implicit_casts have some features we'd want to always enforce, and some we'd like to ignore, for now.
I'd like to propose a stricter_dynamic (name to-be-bike-shedded) variant that combines exactly the rules we need to be successful, without rules that don't add anything for our users. For example, no_implicit_dynamic currently flags this:
void doSomething(List<dynamic> list) {}
void main() {
doSomething([]); // <-- Violates no_implicit_dynamic, but who cares?
}Potential checks
WORK IN PROGRESS: Not exhaustive.
Priority 1
We'd need these checks immediately.
- Disallow
varorfinalwithout a type signature:
class A {
final a; // <-- Error
A(this.a);
}void main() {
var a; // <-- Error
}Priority 2
We'd like to see these checks after all P1 checks land.
- Disallow invoking anything on a
dynamicobject:
void doSomething(dynamic something) {
print(something.length); // <-- Error
}... more TBD ...
I'll be meeting with @jmesserly and others around details of what we enable/what we don't. One important note is that is OK for this new "stricter_dynamic" to not be "strictest_dynamic", it's something we can evolve over time (add more rules as they prove valuable, especially inside Google).