extension type support for unnecessary_constructor_name#4677
Conversation
duplicate_constructorunnecessary_constructor_name
| if (node.parent is ExtensionTypeDeclaration) return; | ||
| var parent = node.parent; | ||
| if (parent is ExtensionTypeDeclaration && | ||
| parent.representation.constructorName == null) { |
There was a problem hiding this comment.
I still don't understand why this condition exists. If I have
class C {
C();
C.new(int x);
}
Then I believe we'll still flag the new in the second constructor. (In other words, I don't think this lint checks to ensure that this is the first and only unnamed constructor.) I don't know why we'd do that for extension types if we're not doing that for classes.
Also, I think we need to visitRepresentationDeclaration in order to catch the use of .new there.
There was a problem hiding this comment.
You're effectively checking the primary constructor in visitExtensionTypeDeclaration, though using visitRepresentationDeclaration might be slightly more direct and more general.
There was a problem hiding this comment.
You're effectively checking the primary constructor in visitExtensionTypeDeclaration, though using visitRepresentationDeclaration might be slightly more direct and more general.
You're right! Better still might even be visitRepresentationConstructorName -- which I hadn't noticed until just now.
I don't know why we'd do that for extension types if we're not doing that for classes.
No good reason except that I'm paying attention now. I overlooked the class case and think it's a false positive that should be fixed (for the same reasons).
There was a problem hiding this comment.
In the end, if you think we shouldn't bother suppressing the lint in case a compilation error is being reported, I'm happy to update. Assuming that is the desire behavior, I added a failing test for the class case so we can swing back and fix it later.
There was a problem hiding this comment.
As long as it gets fixed everywhere I'm fine with not double reporting.
But doing so might require visiting every kind of declaration that can have constructors so that we can set a flag indicating whether we've already seen an unnamed constructor, so that might change the way we want to handle the primary constructor.
There was a problem hiding this comment.
Yeah. That was my thinking too. I didn't want to tackle such a rewrite here so I left a test as a breadcrumb. Happy to rollback the logic for extension types if you'd rather keep the support symmetrical.
There was a problem hiding this comment.
No, as long as we're planning on moving in that direction I'm fine with it being in-progress.
Fixes dart-lang/sdk#59249
/cc @bwilkerson