HaxeFoundation / HaxeFoundation/haxe

[eval] enum abstract with @:native

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

Description

Compiling the following test with `haxe --run Test` fails with the error:
`Field index for fromString not found on prototype MyType`

```haxe
class Test {
static function main()
{
var myType = MyType.ONE;
trace(myType);

myType = "two";
trace(myType);
}
}

@:native("MyType")
enum abstract MyType(String) to String {
public var ONE = "one";
public var TWO = "two";

@:from static public function fromString(str:String):MyType {
return cast str;
}
}
```

Removing `@:native` or renaming the value inside it seems to fix it.

Tested and working at least on js. neko, java, cpp, hl.

haxe 4 preview 5 (latest from git)

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.