HaxeFoundation / HaxeFoundation/haxe
Final and child classes
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
With 4.1.x, I cannot use `final` on a field that is meant to be set in child classes' constructor (`ReactComponent`'s `state` in react):
```haxe
class Main extends Base {
public function new() {
super();
test = true; // Cannot access field or identifier test for writing
}
static function main() {
new Main();
}
}
class Base {
final test:Bool;
function new() {
test = false; // Added so that compiler doesn't complain, but this part is actually not needed/wanted
}
}
```
What I'd want would be a `final` that only allows assignment in constructors, even if it's a child class' constructor. Note that if it's needed that base class don't assign it for this to work, it's ok for my use case (similar to abstract classes).
Workaround would be a `@:bypassFinal` or something, and I'd add it via macro.
Contributor guide
Assessment
This issue has not been assessed yet.