HaxeFoundation / HaxeFoundation/haxe
final incompatible with haxe.Unserializer
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
There's a frustrating intersection between `final` variables only being settable at declaration or in the constructor, and `haxe.Unserializer` creating empty instances, requiring initialization outside of the class constructor. This essentially precludes the use of `final` on any class that we wish to use serialization with.
Maybe we could add some kind of metadata to indicate that initialization should be allowed from another function, not just `new()`. Maybe there's another way to tackle this.
I'm testing on Haxe 4.0.0-rc.2. Here's what I'm trying to do:
```haxe
class Main {
static function main() {
var unserializer = new Unserializer(data);
}
}
class Tweenable {
public function new() { }
}
class Thing {
public final x:Tweenable;
public function new() {
// This would work:
x = new Tweenable();
initialize();
}
private function initialize():Void {
// But we need this, and it doesn't
x = new Tweenable();
}
@:allowInitialization
@:keep
public function hxUnserialize(unserializer:Unserializer) {
initialize();
// ...
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.