HaxeFoundation / HaxeFoundation/haxe
Override and default types
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Look at the following sample:
```haxe
class A {
public var x : Int;
public function foo( v : A ) : Int {
return v.x;
}
}
class B extends A {
override function foo(v) return v.x * 2;
}
class Test {
static function main() {
var x : B = null;
x.foo({ x : 0 });
}
}
```
In this case, we somewhat innocently changed the type of B.foo to be more general that what it should be.
Sadly, in HashLink and some other static platforms, this will create an allocation for each call of foo because we're casting an "A" to "{ x:Int}".
I think the override argument types should be inherited by default from the super class definition if they have no explicit type. That would both improve the completion and avoid this kind of hidden error.
Contributor guide
Assessment
This issue has not been assessed yet.