Linter: False negative `prefer_const_constructors` seems to be random to occur

Created on 1 Oct 2019  ·  9Comments  ·  Source: dart-lang/linter

Describe the issue
When the codes have prefer_const_constructors issues, the linter may or may not find the issues every time it runs.
So CI may DO find this kind of issue even if the local envs DO NOT.
I don't find this problem regarding the other rules so far.

Flutter versions in CI and locals are the same.

❯ flutter analyze --version
Flutter 1.9.1+hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2d2a1ffec9 (4 weeks ago) • 2019-09-06 18:39:49 -0700
Engine • revision b863200c37
Tools • Dart 2.5.0

To Reproduce
Anywhere to violate prefer_const_constructors.

Expected behavior
The linter should always find the same issues in the same codes.

bug

Most helpful comment

We fixed an issue in analyzer that might be causing this one, but we cannot be sure, because we were not able to reproduce this one.

All 9 comments

Weird!

@scheglov: curious if you have any thoughts on where indeterminacy could be coming from?

Also, I notice this note

https://github.com/dart-lang/linter/blob/df8d16804e1a95640f8dc3324de9380df738ed8f/lib/src/rules/prefer_const_constructors.dart#L104

Do you recall why we needed this hack? Can we safely remove it?

Not really actionable :-(
If there is a test case, I can look.

A guess would be that it depends on whether we resynthesize element model from summaries or resolve the unit.

Yes, I think we can remove this check for type parameters from linter.
Analyzer does it with https://dart-review.googlesource.com/c/sdk/+/116600

I run into this a lot. I have yet to be able to find a reproducible test case, but it definitely happens. It seems to be dependent on the shape of the code sometimes, like, I'll add some code somewhere and that will cause it to find more places that need const.

We fixed an issue in analyzer that might be causing this one, but we cannot be sure, because we were not able to reproduce this one.

Since we've found and fixed an analyzer bug that seems credibly related to this, and there's been no further activity on this bug, I'm assuming this is fixed. @Masaokb @Hixie if you're still seeing problems using a dev build that's more recent than March 23, please feel free to re-open.

I still experience this issue on Flutter 1.17.5 stable channel. Locally when I run flutter analyze, no issues are found. But when the CI server (Codemagic) pulls and runs flutter analyze, it finds these prefer_const_* issues.

Thanks for the report. And sorry for the continued hassle. We've had a hard time reproducing this issue reliably. Any ideas here would be a huge help. Thanks!

... when the CI server (Codemagic) pulls and runs flutter analyze ...

Which version of Flutter is the CI server using?

I just found the cause of the issue in this instance. The CI server was configured to automatically use the latest version of the flutter stable channel, in this case 1.20.0, but my local machine was using 1.17.5. After upgrading to the latest version, the lint warnings showed on my machine and I fixed them.

On 1.17.5 though, flutter analyze would sometimes detect issues but once you switched to the affected file, the lint warnings would vanish. Since, 1.20.0 is reporting the warnings that were missed in previous versions, I'm sure this would happen less often if not at all. Thanks to all flutter contributors for this update. 👍🏾

Was this page helpful?
0 / 5 - 0 ratings