-
Notifications
You must be signed in to change notification settings - Fork 205
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
Allow overriding extensions from extensions on subclasses #1127
Comments
My use case has to do with my assertions library, should: https://pub.dev/packages/should I would like to a) be able to delegate some assertions to type-specific handlers and b) allow users to define their own type-specific handlers. This is possible without using extension methods, but becomes impossible using extension methods. |
You can't, actually. That extension is always going to be shadowed by the instance
That's actually also not correct. The extension What won't happen is dynamic dispatch (which I guess is what you are asking for): The The lint is confused, because not only is |
Thanks for clearing this up. I'll have to do some research as to why my code isn't working then. |
FYI, #177 is a proposal for an enhanced extension feature which is aimed specifically at supporting late binding for extension methods. |
I realize that the title is somewhat vague/difficult to parse, so let me explain what I mean. When we have an extension method, we can override members of super-classes:
However, if those members were defined in an extension themself, the code breaks down:
As a package developer trying to support extensions, user-defined integration, and type support in the same package, I've been butting my head into a wall due to this issue.
I recognize that this is a section of the larger extension conflicts issue; I would contend that, in this particular case, given the
@override
marker, the compiler should be allowed to automatically delegate calls to the subclass extension.Another syntactical suggestion, which might ease the load on the compiler and reduce unnecessary inference:
Where Foo's extension-ed type must be a subclass of Bar's extension-ed type.
The text was updated successfully, but these errors were encountered: