-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lint prefer_is_empty: List.isEmpty is not a const expression #57805
Comments
@leafpetersen @lrhn For the language question. |
Actually We could extend to also allowing |
@hugovdm Can you provide an example of where the rule is producing a lint where it shouldn't? |
Here is a List length assert that seems to pass without problems: My unit tests include constructing a const Locale with an empty list: Running ci/build.sh, I get this lint error:
$ out/host_debug_unopt/dart --version |
And by comparison, if I change it to isEmpty as per the lint suggestion, this is the result:
|
Thanks! Unfortunately, those links are broken so I can't see the examples. |
The # got swallowed. I've edited the original, and I'm trying proper Markdown this time: |
Thanks! That code definitely looks invalid to me, and analyzer seems to confirm that by producing an error. The lint rule should probably be updated to not generate a lint in this case because an error has already been produced, but the error is still there and still valid. |
I'm not sure what you mean by invalid. The code in my branch compiles and runs and unit tests pass? (Only the "variants.isEmpty" version I mentioned yesterday in in this thread fails.) |
My understanding is that the condition in the assert is required to be a potentially constant expression because the assert is in a constructor with the But, after re-reading the spec's discussion of constants, it looks like you're right about
and that the rule needs to not create a lint if |
It's true that So: class C {
final v;
const C(dynamic x) : v = x.length;
} is a valid class. The invocation If the type of
(That would effectively preclude anything but |
This issue affects flutter/sentry (getsentry/sentry-dart#52 (comment)) |
Dart VM version: 2.1.0-dev.7.1.flutter-1f4dfce179 (Fri Oct 12 10:39:28 2018 +0000) on "linux_x64"
Lint suggests "prefer_is_empty". isEmpty doesn't work as a const expression, whereas List.length == 0 does.
I think isEmpty and isNotEmpty should be made to work for const expressions too, if possible?
The text was updated successfully, but these errors were encountered: