-
Notifications
You must be signed in to change notification settings - Fork 214
base mixin
that implements a sealed class
counts towards exhaustiveness. Maybe allow sealed mixin
.
#3103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm guessing exhaustiveness is not transitive through a |
Ok, so according to the specification |
That is correct. Exhaustiveness only propagates through What you can do is: sealed class Sealed {}
enum Enum implements Sealed {
value;
}
enum Enum2 implements Sealed {
value;
}
final class Subclass extends Sealed {}
sealed class Foo implements Sealed {}
mixin _Foo {
// Shared implementation of `Foo` which needs to be mixed in.
}
enum EnumFoo with _Foo implements Foo {
value;
}
int foo(Sealed s) => switch (s) {
Enum _ => 0,
Enum2.value => 0,
Subclass _ => 0,
EnumFoo _ => 0,
};
void main() {
foo(Enum.value);
} That is, the type you want to expose doesn't have to be a mixin. |
This does not actually work because using a private mixin breaks type inference within ternary and switch expressions. And the lack of implements on the mixin means that |
Not sure how the private mixin breaks type inference, but I'm guessing it's our classic "UP is stupid" issue (which could be possibly be at least helped by not including declarations which are inaccessible when finding common superinterfaces). If you want to have sealed class Sealed {}
enum Enum implements Sealed {
value;
}
enum Enum2 implements Sealed {
value;
}
final class Subclass extends Sealed {}
sealed class _UpIsStupid implements Sealed {}
abstract interface class _FooApi {
int get foo;
}
sealed class Foo implements _UpIsStupid, _FooApi {}
mixin _Foo implements _FooApi {
@override
int get foo => 42;
}
enum EnumFoo with _Foo implements Foo {
value;
}
int foo(Sealed s) => switch (s) {
Enum _ => 0,
Enum2.value => 0,
Subclass _ => 0,
EnumFoo _ => 0,
};
void main() {
foo(Enum.value);
} It's something of a workaround, just because you can't have a |
base mixin
that implements a sealed class
counts towards exhaustiveness (& related oddities)base mixin
that implements a sealed class
counts towards exhaustiveness. Maybe allow sealed mixin
.
I agree that |
Another case of this: dart-lang/sdk#53809 |
That doesnt make sense to me. if its that implies that I often find myself wanting to use I see no reason why hell, perhaps the analyzer should just not show anything other than |
Seeing this on
3.1.0-109.0.dev
.Only in Analyzer: Uncommenting Foo, like the enums, complains that the case will never match.
The text was updated successfully, but these errors were encountered: