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 #575

Open
Hixie opened this issue Jan 17, 2019 · 3 comments
Open

Default argument values should imply "const" context #575

Hixie opened this issue Jan 17, 2019 · 3 comments
Labels
enhanced-const Requests or proposals about enhanced constant expressions

Comments

@Hixie
Copy link

Hixie commented Jan 17, 2019

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 dart-lang/sdk#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.

@eernstg
Copy link
Member

eernstg commented Jan 17, 2019

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.)

@srawlins
Copy link
Member

This sounds like it is resolved?

@eernstg
Copy link
Member

eernstg commented Sep 12, 2019

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.

@dart-lang dart-lang deleted a comment from eernstg Sep 12, 2019
@ghost ghost closed this as completed Sep 12, 2019
@lrhn lrhn transferred this issue from dart-lang/sdk Sep 12, 2019
@lrhn lrhn reopened this Sep 12, 2019
@dart-lang dart-lang deleted a comment 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
Projects
None yet
Development

No branches or pull requests

4 participants