-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Stricter strong-mode (especially around dynamic) #30397
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
Comments
In that case what does |
Nothing, except I can't force every library in existence to never use // some_library.dart
dynamic returnMapOrList() => ... // google_code.dart
print(returnMapOrList().length); // <-- Error plz. |
RE, inferring from dynamic: #26781 But from your examples @matanlurey, it sounds like you'd like to prohibit dynamic calls/operation altogether? In that case, there's actually no reason to prohibit List a = [42];
a.removeFirst();
a.add('hi');
print(a[0]); // this is okay
print(a[0].contains('h')); // this is not Prohibiting all dynamic ops is a strong property. It ensure "rename refactoring safety" for example, which is something I've heard folks request. It's a really interesting idea. |
Thanks!
Disallow, or at least require
Sure. I'm carefully separating priorities 1 and 2 though, because I think "1" has a lot of consensus and "2" maybe does not, and I'd like to not let perfect be the enemy of good enough here :) My goal is to see if we can have something called "stricter" strong-mode, that we enable by default in Google, and incrementally add more checks to over time (versus having to write custom lints, etc), instead of needing a breaking change to the default semantics over and over. |
Nice. So there's still a way to opt-in to One of our inspirations for no-implicit-dynamic was C# (disclaimer: I worked on that C# feature way back when). In C# they have an explicit We couldn't figure out a clean way to do this in Dart, because The downside is it makes
Ah, gotcha! That makes sense. Agree, let's get in whatever easy stuff we can first. We can add to the flag over time. |
CC @leafpetersen on this discussion |
FWIW, Flutter (for code we ship, not for user code) does use |
I think we have enough of these issues covered elsewhere. |
Forked from an internal thread.
The
strong-mode: true
flag to static analysis currently has an optional flag,no_implicit_dynamic
, which forces inference ofdynamic
, to be, well, not implicit 😏. On the other hand, it andno_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:Potential checks
WORK IN PROGRESS: Not exhaustive.
Priority 1
We'd need these checks immediately.
var
orfinal
without a type signature:Priority 2
We'd like to see these checks after all P1 checks land.
dynamic
object:... 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).
The text was updated successfully, but these errors were encountered: