dart-lang / dart-lang/language

Disallow metadata on the type parameters of a function type?

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

Description

The common front end constant evaluator does not support metadata on a type parameter of a function type, and it turns out to be rather costly in terms of compilation time if this feature is implemented (because it implies that constant evaluation must traverse all types to find metadata _in_ them, not just _on_ them). Here is an example:

```dart
main() {
void Function<@myMetadata X>(X x) myVariable = (_) {}; // Make this an error?
}
```

Note that this is concerned with function _types_ only, it doesn't affect type parameters that are declared by a generic function:

```dart
void myFunction<@myMetadata X>(X x) {} // OK.
```

A bit of searching in large bodies of source code doesn't produce any hits on likely forms where this feature is used. Also, it crashes the analyzer (cf. dart-lang/sdk#39190).

So I'd propose that we consider making it a compile-time error and check that it doesn't occur, rather than rushing into an implementation of it in every tool.

@askeksa-google, you had some further comments on the performance implications?

WDYT, @leafpetersen, @munificent, @lrhn?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.