HaxeFoundation / HaxeFoundation/haxe

Final and child classes

Open
#9,552 2 comments 0 reactions 0 assignees View on GitHub
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

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.