HaxeFoundation / HaxeFoundation/haxe
invalid code generated when specifying broader type for an override method argument
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
```haxe
class Entity {}
class Building extends Entity {}
class Unit extends Entity {
function shoot(target:Unit) {}
}
class HeavyUnit extends Unit {
override function shoot(target:Entity) {
trace(target);
}
function shootBuilding(building:Building) {
shoot(building);
}
}
```
this generates wrong code for the HeavyUnit methods that only fails at run-time:
```cs
public class HeavyUnit : global::Unit {
public override void shoot(global::Unit __temp_target1) {
global::Entity target = ((global::Entity) (__temp_target1) );
global::haxe.Log.trace.__hx_invoke2_o(default(double), target, default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"shoot", "HeavyUnit", "Main.hx"}, new int[]{1981972957}, new double[]{((double) (10) )}));
}
public virtual void shootBuilding(global::Building building) {
this.shoot(((global::Unit) (((object) (building) )) ));
}
}
```
I guess we could generate an overload for the `shoot` that takes `Entity`, override the `shoot` that takes `Unit` and calls the `Entity` one...
Contributor guide
Assessment
This issue has not been assessed yet.