Skip to content

Stricter strong-mode (especially around dynamic) #30397

@matanlurey

Description

@matanlurey

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 var or final without 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 dynamic object:
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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions