Skip to content

Default initializers on required parameters#4022

Merged
JsonFreeman merged 7 commits into
masterfrom
defaultInitializer
Jul 28, 2015
Merged

Default initializers on required parameters#4022
JsonFreeman merged 7 commits into
masterfrom
defaultInitializer

Conversation

@JsonFreeman

Copy link
Copy Markdown
Contributor

Fixes #3604.

This PR relaxes our rules to allow default initializers to be present on required parameters as well as optional parameters. To be concrete, we allow default initializers on all parameters. To be considered an optional parameter, the parameter must have a question mark, or it must have an initializer and not be followed by a required parameter anywhere in the rest of the signature.

For example, in the following signatures, a is optional:

(a = 0, b = 0);
(a = 0, b?);
(a = 0, ...b);

But in the following signature, a is not optional:

(a = 0, b);

One thing to note is that an optional parameter corresponds to an argument slot that is allowed to be missing. The default initializers for required parameters kick in when undefined is passed, but the argument is not allowed to be omitted entirely.

This should not be a breaking change.

@ahejlsberg

Copy link
Copy Markdown
Member

👍

JsonFreeman added a commit that referenced this pull request Jul 28, 2015
Default initializers on required parameters
@JsonFreeman JsonFreeman merged commit bbadd70 into master Jul 28, 2015
@JsonFreeman JsonFreeman deleted the defaultInitializer branch July 28, 2015 22:27
@danquirk

Copy link
Copy Markdown
Member

@JsonFreeman do we have any issue tracking the associated spec change? :)

@JsonFreeman

Copy link
Copy Markdown
Contributor Author

Oh man, I keep forgetting. And you always catch it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants