-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
analyzer should show an error when casting to a non-overlapping type #58803
Comments
This is working as intended, and it is certainly possible for such casts to succeed: class A {}
class B {}
class AB implements A, B {}
void main() {
A a = AB();
a as B;
print('Did not throw!');
} |
I made a proposal for a safer variant of casting (for instance, a cast which is supposed to be a downcast could be expressed as such, and then we'd have feedback for the case where it isn't), but I can't find it right now. It could also be a lint, based on the assumption that some organizations would prefer to use the same reasoning as in the TypeScript code here. Edit: dart-lang/language#1622 contains some example extension methods (getters, actually), expressing a few constrained version of |
Say there exists a You can do a double cast Since you're only asking for a warning, it seems like it's a job for a lint. So, I'm marking this as a request for the analyzer, because that's the closest thing in this repository, but it should more likely be a feature request for the linter. |
yeah i didn't say it's impossible for casts like that to succeed, but most of the time it's a mistake. hence the wording in the typescript error message and my OP
imo
sounds good to me, i don't mind whether it's an analyzer error or a lint. i just didn't know where to raise this since some warnings are considered lints and others aren't? #48553 (comment) |
The standard way to make a cast acceptable to the linter is to use |
there should be a warning on casts that are probably wrong, like in typescript
The text was updated successfully, but these errors were encountered: