Consider:
// In pre-null-safety code:
main() {
print(Foo(null));
}
// In modern Dart with pattern support:
class Foo {
final bool b;
Foo(this.b);
}
String f(Foo f) {
switch (f) {
case Foo(b: true): return 'Foo(true)';
case Foo(b: false): return 'Foo(false)';
}
}
This switch isn't actually exhaustive if an instance of Foo can flow in from legacy mode code where b may actually be null. We need to specify how this is handled.
I think the right answer is to have the switch throw a runtime exception if no case matches. The only time this can happen is when legacy code interacts with null safe code. In a fully migrated program, switches can be soundly statically checked for exhaustiveness.
cc @stereotype441
Consider:
This switch isn't actually exhaustive if an instance of
Foocan flow in from legacy mode code wherebmay actually benull. We need to specify how this is handled.I think the right answer is to have the switch throw a runtime exception if no case matches. The only time this can happen is when legacy code interacts with null safe code. In a fully migrated program, switches can be soundly statically checked for exhaustiveness.
cc @stereotype441