Struggles with the Dart type system
Struggles with the Dart type system
How it began: dart_apitool bug fix
It all started with a bug fix in dart_apitool.
The bug was that dart_apitool detected a breaking change on any parameter type change. Most of the time this is correct but consider this change:
/// version 1
void someMethod(String someParameter);
/// version 2a
void someMethod(String? someParameter);
/// version 2b
void someMethod(Object someParameter);
Here the type of the parameter gets changed but in a non-breaking way.
Any already existing call to someMethod
will work with version 2a and version 2b.
The reason for this is that widening the type makes the old type part of the supported type space for that parameter.
Of course this is only valid for types passed in (which is the case for this bug as it describes method parameters).
So the goal was clear: dart_apitool has to check if the old type is assignable to the new type to decide if that change is a breaking change or not.
Read more...