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
// In pre-null-safety code:main() {
print(Foo(null));
}
// In modern Dart with pattern support:classFoo {
finalbool b;
Foo(this.b);
}
Stringf(Foo f) {
switch (f) {
caseFoo(b:true):return'Foo(true)';
caseFoo(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.
Note: a similar question came up during the work on null safety (with regard to enum-based switch statements), and we decided that it should throw: #1143 (comment)
Consider:
This switch isn't actually exhaustive if an instance of
Foo
can flow in from legacy mode code whereb
may 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
The text was updated successfully, but these errors were encountered: