Open JCKodel opened 1 year ago
This happens because void
is a top type, and when overriding a method you can override it with any type that is a subtype of the base method.
For a more detailed discussion, see this commentary on a similar issue.
Also, there's already a lint proposal for this case: https://github.com/dart-lang/sdk/issues/58081
Sample code:
I was building a Flutter package and I made a mistake: my package required a
void Function()
but I provided aFuture<void> Function()
in a subclass.So, while running my code, the order of execution didn't make any sense:
B was run after C (I know why: it is because I made a mistake by changing the preInitialize method to be async (even though it isn't in the interface/base class). Code analysis should warn me somehow)
So, the code analysis never said anything about this (changing the overridden signature from
void
toFuture<void>
), leading to a mistake where some function required some result from an inheritance that was called later, making asuper
call be out-of-sync with my expectations.My analysis_options.yaml: