-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Extension types] diagnostic when implementing a class with a conflicting member #53567
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
Comments
Assuming that the spec doesn't already dictate a diagnostic like Though I think it wants to be reported on either the declaration of the field I don't like option 2 because |
In general, an extension type can support implicit "forwarding" of member accesses using This situation could be considered to be particularly confusing because we don't have a normal declaration of an instance variable (like the ones we had in several earlier versions of the extension types feature), and hence the representation variable looks like an exception. However, if we have a lint that flags redeclarations with no |
@bwilkerson wrote:
Extension types have all the normal kinds of conflict diagnostics (regular name clashes in the same body scope plus 'class member conflicts' like having an (inherited) instance member with basename The difference between classes/mixins and extension types is that the latter don't require an override relationship when an instance member declaration named We could lint situations where a redeclaration is particularly different from what is allowed in a class/mixin, e.g., when a method is redeclared by a getter or vice versa. We could even lint the situation where a redeclaration wouldn't be a correct override if it had occurred in a class/mixin (for instance, when |
As Erik says, there is no conflict here, it's just a shadowing declaration in the extension type, unrelated to the inherited member it shadows. The representation object getter is just a normal extension type member, could be implemented as So no error, and no intent to make it an error. The "annotate-redeclares" lint should cover this just like any other extension member introduced by the extension type declaration.. |
Thanks. I know that members of the extension type don't override members from inherited types; I regularly remind other people of that fact. But it seems that knowing this doesn't keep me from being tripped up occasionally. I have to wonder how often users will be confused by the semantics. But I do like the idea of making this part of the |
Putting the extension type E(@redeclare C c) implements C {}
class C {
void c() {}
} |
I think we could get used to that (if it is used at all in practice). Hopefully it will be used very rarely in practice. As @lrhn mentioned, a developer who really wants to access the representation object using a redeclared name could just use another getter: extension type E(C it) implements C {
/// ... explaining why this naming is a good idea ...
@redeclare
C get c => it;
}
class C {
void c() {}
} |
Hi @pq, as noted above, it looks like this is not a conflict, but we could enforce the lint rule about |
Thanks for following up on this! I don't believe it is enforced. Seems reasonable though. |
We do have the annotation defined and we warn if it's used where it shouldn't be, but I don't see an error code for flagging redeclaring members that aren't annotated. I think we want to finish this arc of work before the feature ships. |
I believe the warning should be enabled by a lint, probably something like |
You're right, that's what we agreed on and what was implemented. In which case this issue is complete. |
Consider the following:
Can you spot the problem?
The issue becomes apparent when you try and invoke
c()
:and you see an
invocation_of_non_function_expression
diagnostic.Potentially I see two possible improvements:
E
, nudging you to renamec
to not collide withvoid c()
, and.c()
(For 2, I'm thinking something more like how we report field and method conflicts
CONFLICTING_FIELD_AND_METHOD
.)/cc @bwilkerson @scheglov @srawlins @dart-lang/language-team
The text was updated successfully, but these errors were encountered: