Skip to content
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

Constructor tear-off working spec does not discuss unnamed and "new" named collision #1645

Closed
srawlins opened this issue May 21, 2021 · 4 comments
Labels
bug There is a mistake in the language specification or in an active document

Comments

@srawlins
Copy link
Member

srawlins commented May 21, 2021

(I'm opening a new issue as this is an issue with the current spec; #1564 is a pretty long thread so I didn't want to rat-hole over there.)

https://github.com/dart-lang/language/blob/master/working/0216%20-%20constructor%20tearoffs/proposal.md

contains:

This proposal is non-breaking and backwards compatible. Where we introduce new syntactic ambiguities, we retain the current interpretation.

  1. I don't think this is correct. If a class currently has an unnamed constructor and a named constructor named "new", what happens when it upgrades to the constructor tearoff language feature? This presumably will not be allowed with the constructor tearoffs language feature.

  2. The spec does not specify any errors when a class declares an unnamed constructor and a constructor named new.

  3. The spec does not specify any errors when a class declares a static method, getter, setter, or field named new. Should there be? Can an extension on a class declare a static method (or getter or setter) named new? (This seems OK) Can a mixin? Can they only not declare these in a class with an unnamed constructor?

The answers to these questions may encourage some new compile-time warnings ahead of the language feature, and I'd love to know if we should be implementing these ASAP.

@srawlins srawlins added the bug There is a mistake in the language specification or in an active document label May 21, 2021
@leafpetersen
Copy link
Member

  1. I don't think this is correct. If a class currently has an unnamed constructor and a named constructor named "new

I don't understand, new is currently a keyword, and so there can be no existing classes with such a named constructor.

  • The spec does not specify any errors when a class declares an unnamed constructor and a constructor named new.

@lrhn this should probably be addressed

3. The spec does not specify any errors when a class declares a static method, getter, setter, or field named new

Again, new is a keyword, so I believe errors here are specified (cc @eernstg ) and are certainly implemented. Do you have a case where we are not currently emitting an error?

@srawlins
Copy link
Member Author

I don't understand, new is currently a keyword, and so there can be no existing classes with such a named constructor.

Excellent.

Again, new is a keyword, so I believe errors here are specified (cc @eernstg ) and are certainly implemented. Do you have a case where we are not currently emitting an error?

Excellent. No I don't have any cases; looks like the correct error is being reported everywhere.

@lrhn
Copy link
Member

lrhn commented May 22, 2021

Good point that we should be explicit about unnamed/named-new being the same constructor, and it's an error to have two of them.

@srawlins
Copy link
Member Author

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is a mistake in the language specification or in an active document
Projects
None yet
Development

No branches or pull requests

3 participants