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

Default argument values should imply "const" context #574

Closed
ghost opened this issue Sep 12, 2019 · 4 comments
Closed

Default argument values should imply "const" context #574

ghost opened this issue Sep 12, 2019 · 4 comments
Labels
enhanced-const Requests or proposals about enhanced constant expressions feature Proposed language feature that solves one or more problems

Comments

@ghost
Copy link

ghost commented Sep 12, 2019

@Hixie commented on Jan 17, 2019, 7:03 AM UTC:

If you run this:

class Test {
  Test({ this.test = Duration(minutes: 1) }); // the default value is not explicitly "const"
  final Duration test;
}

void main() {
  Test();
}

...you get an exception (a bad one, currently, see #35683).

I think the fact that only a constant is allowed to be used there should imply a constant context and thus make the "const" redundant and implied.

This issue was moved by eernstg from dart-lang/sdk#35684.

@ghost
Copy link
Author

ghost commented Sep 12, 2019

@eernstg commented on Jan 17, 2019, 8:09 AM UTC:

It is by design not a constant context: The language team wanted to keep the door open for language extensions whereby default values could be ordinary expressions that would be computed (the tricky part: in which scope?) at invocation. This would turn into a breaking change if we had allowed C c = C() to mean C c = const C().

(You could say that we have also kept the door open for making it a constant context, should that turn out to be more useful.)

@ghost
Copy link
Author

ghost commented Sep 12, 2019

@srawlins commented on Sep 12, 2019, 3:42 PM UTC:

This sounds like it is resolved?

@ghost
Copy link
Author

ghost commented Sep 12, 2019

@eernstg commented on Sep 12, 2019, 4:35 PM UTC:

Well, considered as a language request we could still go two ways: (1) allow more general expressions (e.g., evaluated at each invocation) as default values, in which case it makes sense that this is not a constant context, or (2) decide that we won't do that (so default values must be constant), and then make it a constant context such that const can be omitted.

I think the proper thing to do would be to move it to the language repo. If a lot of people have a strong preference about this decision then this issue then they can use this issue to make it known.

@eernstg eernstg added the feature Proposed language feature that solves one or more problems label Sep 12, 2019
@lrhn
Copy link
Member

lrhn commented Sep 12, 2019

Closing this in preference for #575 (moved by github).

@lrhn lrhn closed this as completed Sep 12, 2019
@eernstg eernstg added the enhanced-const Requests or proposals about enhanced constant expressions label Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhanced-const Requests or proposals about enhanced constant expressions feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants