-
Notifications
You must be signed in to change notification settings - Fork 209
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
Disallow overriding of runtimeType #4283
Comments
I once investigating overriding I didn't go with it in the end though. |
The original discussion dates back to 2013: https://groups.google.com/u/1/a/dartlang.org/g/misc/c/XZbhI1N9Ads/m/HQtmawfJDB0J |
... yeah I only think we should disallow this more now 🤣 |
I had this case in a Flutter project which required overriding Flutter's I opened an issue (flutter/flutter#146504), but it was rejected, so I still rely on overriding |
It's used internally to make Other classes can choose to hide implementation classes in the same way. But why? That only makes sense if someone uses If we could require Personally I'd rather remove |
Maybe make it a lint warning instead and let people be able to do it if they can't find another way to solve their issue at hand? I also feel this is ugly, but if it's not breaking anything in the language, or is a big known source of bugs, then I would advise to only have it as a lint and add this lint to the main lint package that ship with Flutter. |
It just seems massively hacky to do anything to this other than return the actual runtime type of the object. I can't possibly see any actual good coming from overriding it? At best it might hack around something that would be better solved another way... and its going to create some very surprising bugs in who knows what other code. |
Not overriding it certainly leads to better debuggability IMO. I personally quite enjoy how |
github search shows quite a few overrides of runtimeType in dart sdk, Pretty common in js_runtime. |
And yet we already do so ourselves. Something must be flawed in that conclusion. Can anything bad come from overriding it? In our own case the good that does come out of overriding it is to hide a private (and platform-specific) subclass from users. Without that If the SDK couldn't do that, that would make the So there is a use for overriding. And the SDK isn't the only libraries having hidden implementation types. |
The existence of code has no bearing on its quality. Are there examples that you would defend as good code?
And that is perfectly fine, what is the point of that code if not to compare the actual runtime type? The assertion failing here would be a feature.
It is also harmful for debug printing, it makes it hard to figure out what a thing actually is. |
And that is why type checks exist and should be used for this purpose. |
What purpose should |
We should consider blocking overrides of runtimeType, as a language versioned change so it can be considered non-breaking. Existing code will work until the language version they are currently on is no longer supported, which is anyways breaking.
Is there any valid use case for overriding
runtimeType
?There was some previous discussion here #3357, but it feels deserving of its own issue.
The text was updated successfully, but these errors were encountered: