HaxeFoundation / HaxeFoundation/haxe

`typedef` with some special methods not works on `jvm` target

Open
#10,077 2 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
platform-jvm
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

The code below show the matter:
``` haxe
// Test.hx

import haxe.iterators.ArrayIterator;

typedef Typedef1 = {function next():V;};
typedef Typedef2 = {function next():V;};
typedef TestHasNext = {function hasNext():Bool;};
typedef TestHasNextNoGeneric = {function hasNext():Bool;};
typedef TestIterator = {function iterator():V;};
typedef TestIteratorNoGeneric = {function iterator():Int;}; // no `$Interface`
typedef TestOtherFunc = {function func():V;}; // no `$Interface`
typedef MyIterable = {iterator:() -> ArrayIterator};
typedef MyIterableInherit = {> Iterable, arrayIterator:() -> ArrayIterator};

class Test {
public static function main() {
var obj:Typedef2 = {next: () -> "test typedef with generic and `next` function"};
trace(cast(obj : Typedef1)); // `jvm` target not works?

var iter:MyIterable = {iterator: () -> [].iterator()};
trace(cast(iter : Iterable)); // not inherit `Iterable$Interface`?

var iter:MyIterableInherit = {iterator: () -> [].iterator(), arrayIterator: () -> [].iterator()};
trace(cast(iter : Iterable)); // WTF?
}
}

```

``` hxml
# compile.hxml

--main Test
--library hxjava
--each

# Java
--java bin/jv
--cmd java -jar bin/jv/Test.jar
--next

# jvm
--jvm bin/jvm/main.jar
--cmd java -jar bin/jvm/main.jar

```

When compiled above code on `jvm` target, the classes files in the output `.jar` package would be like:
![image](https://user-images.githubusercontent.com/12682063/104944990-fdcd9b00-59f2-11eb-9796-fad18956d43b.png)

Then if we try to execute the `.jar`, it would crashed and throw `Exception in thread "main" java.lang.ClassCastException: haxe.root.Typedef1 cannot be cast to haxe.root.Typedef2$Interface`.

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.