Inconsistent results found during CI for prefer_const_literals_to_create_immutables (Windows and Linux). The analyzer on Linux didn't report the linting error.
See https://github.com/flutter/gallery/runs/567366721. Please let me know if any information you need isn't found in the CI logs
@scheglov: is this maybe LinterContext related?
It resembles https://dart-review.googlesource.com/c/sdk/+/142581, but not exactly.
LinterContext.canBeConst() does promise that it will pretend that something is const and check if this would be OK. So, it is up to analyzer to ensure that constant variables that are newly referenced, are evaluated. We don't evaluate all possible constant variables in dependencies - many of them are never referenced, so evaluating all of them will be a waste.
OTOH, evaluateConstant is for something that is already a constant, or probably a constant. If linter itself made something a constant, analyzer does not know about this.
I see two possible solutions: (1) extend canBeConst to accept not only InstanceCreationExpression, but also TypedLiteral; (2) add a flag to evaluateConstant to force computing dependencies. (1) looks better to me.
I agree; extending canBeConst would be best.
(1) extend canBeConst to accept not only InstanceCreationExpression, but also TypedLiteral
This gets my vote.
Thanks for the follow-up!