dart-lang / dart-lang/language

Deprecate function formal parameters and function type aliases.

Open
#2,901 5 comments 10 reactions 0 assignees View on GitHub
dart-4.0 feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

There are syntactical constructs that are discouraged from being used by the following lints: [use_function_type_syntax_for_parameters](https://dart.dev/tools/linter-rules/use_function_type_syntax_for_parameters) as well as [prefer_generic_function_type_aliases](https://dart.dev/tools/linter-rules/prefer_generic_function_type_aliases)

Because they can be replaced with other syntax e.g. with function types, I'd like to propose for function formal parameters (and related syntax) to be deprecated and eventually removed.

```
functionFormalParameter
: COVARIANT? type? identifier formalParameterPart '?'?
;

fieldFormalParameter
: finalConstVarOrType? THIS '.' identifier (formalParameterPart '?'?)?
;

superFormalParameter
: type? SUPER '.' identifier (formalParameterPart '?'?)?
;

typeAlias
: TYPEDEF typeIdentifier typeParameters? '=' type ';'
| TYPEDEF functionTypeAlias
;

functionTypeAlias
: functionPrefix formalParameterPart ';'
;
```

would be adjusted to:

```
fieldFormalParameter
: finalConstVarOrType? THIS '.' identifier
;

superFormalParameter
: type? SUPER '.' identifier
;

typeAlias
: TYPEDEF typeIdentifier typeParameters? '=' type ';'
;
```

i.e.

* `functionFormalParameter` would be removed
* `functionTypeAlias` would be removed
* the optional trailing `(formalParameterPart '?'?)?` would be removed from `fieldFormalParameter` and `superFormalParameter`
* there would only be one way to construct a type alias because there would be one type of type alias left.

This would:

* simplify the grammar and therefore all related infrastructure (parsing, linting, analysis, ...).
* make Dart simpler to learn by explicitly answering the question `which syntax should I use?`

Fixes are already available for both lints.

_Here's the PR that introduced use_function_type_syntax_for_parameters https://github.com/dart-lang/linter/pull/1244_
_Here are the PRs that introduced prefer_generic_function_type_aliases [final PR](https://github.com/dart-lang/linter/pull/945) [first draft](https://github.com/dart-lang/linter/pull/945)._
_The styleguide recommends to **avoid** the old syntax [here](https://dart.dev/guides/language/effective-dart/design#dont-use-the-legacy-typedef-syntax) and [here](https://dart.dev/guides/language/effective-dart/design#prefer-using-function-type-syntax-for-parameters)_

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the listed grammar productions and the two referenced linter rules, then read the linked linter pull requests and the cited styleguide sections. Trace how function formal parameters and legacy function type aliases are represented across parsing, linting, and analysis. Done means the proposed constructs are deprecated or removed consistently and the related infrastructure is updated.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.