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

Optional new and const for Dart 2 (meta issue) #30921

Open
6 of 7 tasks
lrhn opened this issue Sep 28, 2017 · 23 comments
Open
6 of 7 tasks

Optional new and const for Dart 2 (meta issue) #30921

lrhn opened this issue Sep 28, 2017 · 23 comments
Assignees
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...).

Comments

@lrhn
Copy link
Member

lrhn commented Sep 28, 2017

Dart 2 will make new and const operators optional in some cases. The feature is described in https://github.com/dart-lang/sdk/blob/master/docs/language/informal/implicit-creation.md.

This feature needs support from, at least, the common front-end. The kernel compiler can, and likely will, generate the same kernel code whether an optional new or const is present or not, so back-ends should be unaffected. Effectively, the kernel (or even the parser) can perform automatic "new/const" insertion on the program, as soon as it can recognize an invocation as referring to a constructor rather than a static method.

The feature extends the grammar with syntax that wasn't previously valid, so the formatter likely needs to be prepared for it.
The analyzer may need to be prepared for the different syntax as well.

We will not back-port this feature to non-kernel based backends.

@lrhn lrhn added the area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). label Sep 28, 2017
@lrhn lrhn added this to the 2.0-beta1 milestone Sep 28, 2017
@lrhn lrhn self-assigned this Sep 28, 2017
@dgrove dgrove added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Oct 5, 2017
@bwilkerson
Copy link
Member

@munificent I don't think there's any work for the formatter, but it would be good to double check that.

@eernstg
Copy link
Member

eernstg commented Feb 20, 2018

About the need to adjust the formatter, and possibly other tools: The grammar had to be extended with support for a new construct, namely

constructorInvocation ::=
    typeName typeArguments '.' identifier arguments

and that construct is then used in a couple of places. The point is that we can now have things like C<int>.someName(42), and the ability to have actual type arguments after the class name is new. So every tool that has a parser which hasn't already been updated to handle this will need an update.

@bwilkerson
Copy link
Member

Yep, but the formatter uses the analyzer parser, so I think it's probably fine.

@munificent
Copy link
Member

Turns out there is one case the formatter needs to handle:

SomeGenericClass<int>.someNameConstructor();

I added support for that in dart-lang/dart_style@b89b572.

@dgrove dgrove modified the milestones: (Please move issues from the milestone) 2.0-beta1, Dart2 Beta 3 Mar 22, 2018
@dgrove
Copy link
Contributor

dgrove commented Mar 22, 2018

Actually, since this is the meta issue that has the spec as the long pole, moving to the Dart2 Stable milestone.

@dgrove dgrove modified the milestones: Dart2 Beta 3, Dart2 Stable Mar 22, 2018
@leafpetersen
Copy link
Member

The formal spec bug is the only remaining issue, so closing this out.

@stevenroose
Copy link

Should this also work for factory constructors? I'm getting

NoSuchMethodError: No static method 'from' declared in class 'BigInt'.

when calling BigInt.from(5), f.e.

BigInt.from is an external factory constructor.

@lrhn
Copy link
Member Author

lrhn commented May 14, 2018

It should work for all constructors. How are you running the code?

@stevenroose
Copy link

@lrhn I have Dart v2 installed at /opt/dart-v2 and I run /opt/dart-v2/bin/pub run test.

I could be that pub test runs the dart executable in PATH instead of the one in the same directory.. Can I pass to pub which Dart executable to use?

@zoechi
Copy link
Contributor

zoechi commented May 14, 2018

@stevenroose perhaps dart-lang/pub#1807

@leafpetersen
Copy link
Member

Re-opening to track Angular implementation + communication and validation.

@matanlurey
Copy link
Contributor

Good news. AngularDart has verified, mostly thanks to @MichaelRFairhurst, that optional new/const works at the latest dev SDKs, including in metadata annotations. Here is a sample PR where we removed it from all example applications: angulardart/angular#1408.

@jodinathan
Copy link

jodinathan commented Jun 15, 2018 via email

@dgrove
Copy link
Contributor

dgrove commented Jun 15, 2018

@kwalrath is the docs part of this complete?

@kwalrath
Copy link
Contributor

kwalrath commented Jun 15, 2018

It depends on what you mean by "complete". The language tour has a note that new is optional.

I'm working on a PR to improve on that (making optional new the default in the tour, and adding an example for optional const). In the language tour, optional new is (as of dart-lang/site-www#940) the default, and there's a new example for optional const: www.dartlang.org/guides/language/language-tour#using-constructors

For the rest of the docs and examples, we're planning to wait until dartfmt --fix is out.

Tracking issue: dart-lang/site-www#870

@leafpetersen leafpetersen removed this from the Dart2Stable milestone Jun 18, 2018
@leafpetersen
Copy link
Member

Nothing left here is blocking for Dart 2 here, I think. As soon as dartfmt --fix is available for general use, we should announce this, and encourage people to migrate.

@munificent should we consider adding this to the dartfmt presubmit for the SDK now to start migrating and shaking out bugs? We probably really don't want to do that for tests though, so we'd need some way to exclude them. So maybe better to just start manually converting SDK code?

@munificent
Copy link
Member

So maybe better to just start manually converting SDK code?

Yeah, I think running --fix manually is a better first step.

@natebosch
Copy link
Member

Does the Dart VM read SDK code when you run with dart --no-preview-dart-2?

Does dart2js read SDK code when you compile with dart2js --no-preview-dart-2?

If so, dropping new and const from the SDK is blocked on removing those flags.

@sigmundch
Copy link
Member

Does dart2js read SDK code when you compile with dart2js --no-preview-dart-2?

dart2js does - we use the CFE even in Dart1 mode, and the CFE will parse with the missing new/consts always (it is not hidden under a flag).

@munificent munificent removed the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Jul 11, 2018
@mit-mit
Copy link
Member

mit-mit commented Aug 22, 2018

@lrhn what remains before we can close this as completed?

@lrhn
Copy link
Member Author

lrhn commented Aug 23, 2018

SDK and specification still missing. I guess communication is part of communicating Dart 2.0.

@srawlins
Copy link
Member

Should "Remove new and optional const from SDK code" still be part of this task? This meta issue was a planned feature for Dart 2.0, which has completed. AFAIK, no one intends to do this task any time soon. Especially with all of the work being done on the SDK libraries; this would cause a lot of churn if it landed any time in the next few months.

Close this meta issue?

@Stargator
Copy link
Contributor

@srawlins I would say keep it here as a means of tracking it. That doesn't mean it has to be prioritized higher than the current work on the SDK libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...).
Projects
None yet
Development

No branches or pull requests