dart-lang / dart-lang/language

Specify behavior of external constructors with initializing formals

Open
#571 3 comments 0 reactions 0 assignees View on GitHub
specification
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

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.