Skip to content

Add private named parameters section#7250

Open
conooi wants to merge 14 commits intodart-lang:mainfrom
conooi:private-named-parameters
Open

Add private named parameters section#7250
conooi wants to merge 14 commits intodart-lang:mainfrom
conooi:private-named-parameters

Conversation

@conooi
Copy link
Copy Markdown
Contributor

@conooi conooi commented Apr 15, 2026

Create a new section on the constructors page for the new 3.12 feature Private Named Parameters.


@dart-github-bot
Copy link
Copy Markdown
Collaborator

dart-github-bot commented Apr 15, 2026

Visit the preview URL for this PR (updated for commit e8a9b84):

https://dart-dev--pr7250-private-named-parameters-n56d3tla.web.app

@conooi conooi marked this pull request as ready for review April 23, 2026 23:05
@conooi conooi requested review from munificent and parlough April 23, 2026 23:05
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces documentation and code examples for the new 'Private named parameters' feature in Dart, which allows initializing private fields directly in the constructor parameter list. The changes include updates to the language tour, glossary, and analysis configurations. The review feedback identifies an inconsistent semicolon placement in an enum and suggests a technical correction to the documentation to clarify that the feature also supports super-initializer parameters.

Comment thread site/lib/src/pages/glossary.dart Outdated
Comment thread src/content/language/constructors.md Outdated
Comment on lines +453 to +456
* **Initializing formals only:** Named parameters in Dart generally
cannot be private. This feature is an exception that only applies
to named parameters that are initializing formals (`this._field`).
You cannot use private names for regular named parameters.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The private named parameters feature is not limited to initializing formals (this._field); it also applies to super-initializer parameters (super._field). Updating this constraint will provide a more complete and accurate description of the feature's scope.

Suggested change
* **Initializing formals only:** Named parameters in Dart generally
cannot be private. This feature is an exception that only applies
to named parameters that are initializing formals (`this._field`).
You cannot use private names for regular named parameters.
* Initializing formals and super parameters only: Named parameters in Dart generally
cannot be private. This feature is an exception that only applies
to named parameters that are initializing formals (this._field)
or super-initializer parameters (super._field).

Copy link
Copy Markdown
Member

@munificent munificent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! \o/

Comment thread examples/analysis_options.yaml Outdated
Comment thread site/lib/src/pages/glossary.dart Outdated
Comment thread src/content/language/constructors.md
Comment thread src/content/language/constructors.md Outdated
Comment thread src/content/language/constructors.md
Copy link
Copy Markdown
Member

@parlough parlough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love all these updates @conooi!

A few suggestions to consider, but generally looks great to me.

Comment thread examples/analysis_options.yaml Outdated
Comment thread src/content/language/constructors.md Outdated
Comment thread src/content/language/constructors.md Outdated
Comment thread src/content/language/constructors.md Outdated
Comment thread src/content/language/constructors.md Outdated
Comment thread src/content/language/constructors.md Outdated
Comment thread src/data/glossary.yml
Comment thread src/data/glossary.yml
Comment thread src/content/language/constructors.md Outdated
}
```

### Private named parameters
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name this section and references to this capability as "private-named parameters" to clarify the parameter itself isn't private, but rather the name is?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@munificent thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really just about parameters whose name happens to be private. Dart has already allowed those for positional parameters:

class C {
  int _x;
  C(this._x);
}

It's really about named parameters whose name is private. I thought about calling the feature "private-named named parameters" but that's obviously no fun for anyone to read or say. :) For what it's worth, I think of the feature as "private (named parameters)" more than "(private named) parameters".

But if you think the hyphen will help clarify things for readers, I'm OK with it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the title as is to remain consistent with the feature spec (if that matters). Do you have strong opinions about the hyphen @parlough?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants