HaxeFoundation / HaxeFoundation/hashlink

Null exception when casting with inheritance of depth 2+

Open
#602 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
901
Forks
201
Avg merge
18h 9m
Merged PRs (30d)
8

Description

Casting a subclass of a subclass to their base class will cause a strange "null" exception at line 0 of a random external/standard library.

```haxe
abstract class A {
public abstract function work():Void;
}

abstract class B extends A {

public abstract function work(): Void;
}

class C extends B {
public function new() {}

public function work():Void {
trace("doing");
}
}

class Main {

static function main(){
var c = new C();
var a: A = cast c;
a.work();
}
}
```

Result:

Called from A.work(C:\HaxeToolkit\haxe\std/hl/_std/Date.hx:0)
Called from $Main.main(Main.hx:24)
Called from .init(?:1)

As you can see it strangely fails at "Date.hx:0". Casting to Dynamic instead can be used as a workaround.

The above code snippet works in other targets.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.