-
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
Better message for override
inside extension type
#59855
Comments
An extension type can't override anything, it can only redeclare a member. The difference is that when a member has been overridden, an invocation will always call the most specific implementation of that member, no matter whether that most specific implementation is known from the static type or not. An extension type member is only invoked when it is the statically known declaration for that member name. For example: import 'package:meta/meta.dart';
class C {
C._(this.x);
final int x;
}
extension type E(C c) implements C {
@redeclare
int get x => 0;
} The A redeclaration is much more flexible than an overriding declaration: The redeclaration can be a getter when the redeclared declaration is a method or vice versa (we can't do that in an overriding declaration), and the signatures don't have to be related. The reason why there are no constraints is that the redeclaration is never invoked in a situation where it isn't known statically. In other words, if you're calling a redeclaration then a "jump to declaration" operation in an IDE will take you to the exact piece of code that will run at run time, there will never be a "more specific" redeclaration which will "override" it. So you should simply use |
Ohh, I see. Thanks for the explanation! |
@eernstg would it be reasonable to reopen this as a request for a better message for |
Sounds like a good idea! @bwilkerson, WDYT? |
I agree, a better message would be helpful to users. |
override
inside extension type
While testing a code for #59820 as bellow:
On dartpad set to main, I get:
The getter doesn't override an inherited getter.
I don't think that is true considering
implements C
. Can anyone confirm this?The text was updated successfully, but these errors were encountered: