cascade_invocations: Turning successive method invocations into cascading has sometimes unexpected behavior change #57631
Labels
area-devexp
For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
devexp-linter
Issues with the analyzer's support for the linter package
linter-false-positive
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
This is related to the
cascade_invocations
rule.We recently did a massive refactoring to address the
cascade_invocations
warnings, and found that one of those changes introduced a bug in our code.The
doSomething()
call changes some internal states and then notifies all the listeners, and that includes the_handleEvent()
method. This_handleEvent()
implementation then reads the internal state ofBar
, so it is important that_bar
is correctly assigned before this happens.We changed this to use cascading style instead.
and it started to crash, because
_bar
is not yet assigned when_handleEvent()
is called for the first time due to thedoSomething()
call.We fixed this on our side once we found the issue, but it wasn't an obvious problem to find. I would think it would be difficult for the linter to determine whether it is safe to use cascade or not, but just wanted to call this out as a problem. Also related to #57626, as it's also about the order between the assignment and the method calls on that object.
The text was updated successfully, but these errors were encountered: