dart-lang / dart-lang/language

Make pseudo-privately named actual arguments an error?

Open
#4,062 9 comments 3 reactions 0 assignees View on GitHub
question
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Thanks to @sgrekhov for bringing up this situation.

It is currently a [compile-time error](https://github.com/dart-lang/language/blob/aa8ee9d17b6c1c345ed7fb23a96c8c742cfcbe5c/specification/dartLangSpec.tex#L2416) for a named parameter to have a name whose first character is `_`.

```dart
void f({int _ = 0}) {} // Error.
```

However, it is not reported as a compile-time error when an actual argument is passed to such (non-existing) parameters:

```dart
void main() {
Function f = () {};
try {
f(_pseudoPrivateName: 1); // OK
} catch (_) {}
}
```

Should we make it a compile-time error to use actual arguments with such names?

We [may introduce](https://github.com/dart-lang/language/issues/2509#issuecomment-1539012088) the ability to _declare_ a formal parameter whose name starts with `_`, but we do not (as far as I can see) have any intentions to allow the parameter to have such a name, it's only considered for situations where the formal parameter name will be computed as the 'corresponding public name'. (The corresponding public name is `p` when the declared name is `_p`, but it does not exist when the declared name is `_` or `__` or `_1`, so we only intend to allow formal parameters with such declared names when other constraints are satisfied as well.)

@dart-lang/language-team, WDYT? Should we report `f(_pseudoPrivateName: 1)` as a compile-time error, based on the reasoning that it cannot succeed in current programs, and most likely will never succeed even in future Dart code?

Contributor guide

Open the contributing guide

Research direction

Read the linked Dart language specification section and compare it with the examples of formal and actual named arguments in the issue. Review the discussion and the referenced issue 2509 to determine whether this should become a compile-time error; done means a decided language-design direction and corresponding specification update, if approved.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.