dart-lang / dart-lang/language
Implicit superinitializers shouldn't be added to external constructors
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
The spec currently says the following about superinitializers:
> Let _k_ be a generative constructor.
> Then _k_ may include at most one superinitializer in its initializer list or a compile-time error occurs.
> If no superinitializer is provided, an implicit superinitializer of the form `super()` is added at the end of _k_'s initializer list, unless the enclosing class is class `Object`.
I think an exception needs to be made for external constructors. Given the following library:
```dart
class A {
A.one();
}
class B extends A {
external B.two();
}
```
the analyzer reports that:
> The superclass 'A' doesn't have a zero argument constructor. #no_default_super_constructor
Since `external B.two()` does not specify the initializers or the body that the external declaration will provide, I don't think the implicit superinitializer should be added.
(The text for _external functions_ also includes "An external function is a function whose body is provided separately from its declaration." which I think should also be amended to says "... whose body, and any initializers (for an external constructor) are provided ...")
Contributor guide
Assessment
This issue has not been assessed yet.