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
I didn't understand how the code bellow didn't show any warnings.
This can lead to very hard nested issue when you didn't understand why your switch isn't working as expected and you suddenly see that the value used in the switch can't match any case value...
In big entreprise team with different skill levels, it become a massive issue.
Bellow code of the issue, I deliberately put a dumb examples to be more explicit.
sealedclassUser {
constUser();
}
classConnectedextendsUser {
constConnected();
}
classDisconnectedextendsUser {
constDisconnected();
}
voidtest() {
User user =constConnected();
Widget child =AppBar();
print(switch (user) {
Connected() =>true,
Disconnected() =>true,
AppBar() =>false, // not warning ? This type has nothing in common with User class
});
print(switch (child) {
Connected() =>true, // no warning ? This type has nothing in common with Widget classDisconnected() =>true, // no warning ? This type has nothing in common with Widget classAppBar() =>false,
_ =>throwUnimplementedError(),
});
print(switch (10) {
10=>true,
'10'=>false, // warning well displayed !
_ =>throwUnimplementedError(),
});
}
The text was updated successfully, but these errors were encountered:
You need to mark Connected and Disconnected as final. sealed does not imply finality of subclasses. As written now you can create a subtype of Connected and AppBar in another library.
If you mark all subclasses final you will get the warning.
Hello :) !
I didn't understand how the code bellow didn't show any warnings.
This can lead to very hard nested issue when you didn't understand why your switch isn't working as expected and you suddenly see that the value used in the switch can't match any case value...
In big entreprise team with different skill levels, it become a massive issue.
Bellow code of the issue, I deliberately put a dumb examples to be more explicit.
The text was updated successfully, but these errors were encountered: