You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method jump can be invoked on animal because the type of animal is dynamic.
You probably expected animal is Fish to promote animal such that its type would be Fish in the body of the if statement, but that doesn't happen because instance variables are never promoted (here are a couple of related issues: #34480, #25565).
We expect promotion to be revised in several ways (e.g., we may promote after if (animal is! Fish) return; which means that the control flow analysis is made stronger). But promotion of mutable instance variables is not so likely to happen, because any invocation of a method or function may allow such instance variables to be mutated and hence invalidate the type that we just tested for.
It would be useful to have the property that all promotions are associated with explicit syntactic constructs, which could mean that anything like if (animal is Fish) ... would be flagged (with a lint, hint, or something like that) because it does not promote animal. But that would be a breaking change and there could be many situations in existing code where such diagnostics would just be annoying noise. So there is no easy way to detect and report the situations where promotion was intended and expected, but didn't happen.
In below example, the Dart analyzer did not show any errors:
The text was updated successfully, but these errors were encountered: