-
Notifications
You must be signed in to change notification settings - Fork 207
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
Dynamic variable values can utilize extension functionality. #4225
Comments
https://dart.dev/language/extension-methods#static-types-and-dynamic
|
Should we allow extension method invocations on It would still be a top type, so only extensions that work on all objects would apply. It's probably a bad idea. Maybe the analyzer could warm if a dynamic never invocation has a name that is probably meant to be an extension member (there is one in scope that would apply, and no obvious instance members with the same name.) |
IMO And there's a lint for catching dynamic invocations. As such, the linter would tell you that |
Using the |
I am genuinely curious what these are and I do think we should be asking ourselves how important they are. Having dynamic invocations dramatically complicates the language, with every feature having to take them into account, and I can't recall ever actually needing one, they just let you be lazy. |
+1 There's one |
And this is a horrible API lol. It should have exposed an interface for that and then done a type check. |
Unfortunately, it's too breaking to change it now, so I don't see it happening... |
Sure, I agree with that in general. Removing dynamic as a whole falls into this category almost certainly, at least until a breaking version of the language. |
My hope is to be able to add methods in classes with augmentations or macros, then extension types working with dynamic would be possible. I'm not sure if augmentations will be powerful enough. For example: we are not allowed to add a |
There are a few other dynamic usages in the SDK 🔥 I'm quite proud of knowing such useless information :p Still, I think deprecating This could be done by making sure the lint discouraging dynamic invocations is enabled by default (and possibly with a tweaked message) |
There are also |
I think we could deprecate dynamic completely as long as we have some kind of structural-typing. So, for instance, we could introduce a |
Dynamic variable values can utilize extension functionality.
It is mainly used to act like Kotlin's let extension function, making it convenient to check whether a dynamic value is null or to check its type.
The biggest problem now is that it works perfectly fine when running variables of other types, but a NoSuchMethodError will be reported when running the values of dynamic variables.
You can see more in :Dartpad demo
The text was updated successfully, but these errors were encountered: