dart-lang / dart-lang/language
Specify behavior of external constructors with initializing formals
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
The specification for `external` functions is mostly grammatical. This prevents `external` functions from having bodies and `external` constructors from redirecting or having initializer lists, but doesn't account for `external` (non-redirecting, generative) constructors with initializing formals. Such constructors should be erroneous, but as far as I can tell, the type of error is never specified.
---
For context, analyzer and CFE disagree on the following:
```dart
class Foo {
int x;
external Foo(this.x);
}
```
Analyzer finds no issues (and leaves it to backends to produce a runtime error), while CFE reports `Error: An external constructor can't initialize fields.`
---
IMO this should at least be a compile-time error. The grammar could be rewritten to make this syntactically invalid, but that may not be worth it.
Contributor guide
Assessment
This issue has not been assessed yet.