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

Non-const default values for static / top-level methods #3687

Closed
DartBot opened this issue Jun 15, 2012 · 6 comments

Comments

@DartBot
Copy link

commented Jun 15, 2012

This issue was originally filed by @seaneagan


It would be nice if parameter default values of static/top-level methods could be lazily initialized, probably on the first time the method is called without passing the parameter, the same way that static variables are. For example, you may want to have a parameter default value be the value of a static variable which is lazily initialized.

@sethladd

This comment has been minimized.

Copy link
Member

commented Jun 15, 2012

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@floitschG

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2012

This probably leads to unexpected behavior:
foo([x = new Map()]) { ... }

If we implement lazy initialization for default-values as you describe we would allocate the map only once. This is, however, completely contrary to what most programmers would expect.

@DartBot

This comment has been minimized.

Copy link
Author

commented Jun 19, 2012

This comment was originally written by @seaneagan


Agree. Any non-constant default value expression should be evaluated on each invocation. That would definitely be useful, and help to better document many APIs, but can probably wait until after M1.

@gbracha

This comment has been minimized.

Copy link
Contributor

commented Jun 26, 2012

Set owner to @gbracha.
Added this to the Later milestone.
Added Accepted label.

@kasperl

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@kevmoo kevmoo added P2 type-enhancement and removed accepted labels Feb 29, 2016

@munificent munificent changed the title non-constant parameter default values for static / top-level methods Non-const default values for static / top-level methods Dec 19, 2016

@matanlurey matanlurey closed this Jun 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.