HaxeFoundation / HaxeFoundation/haxe

method_dyn missing when using @:unreflective and @:nativeGen with listener callback

Open
#12,437 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

This issue happens when `@:unreflective` is used on the class and a method reference is passed to addEventListener().
The generated C++ still tries to call method_dyn, so compilation fails.

Removing `@:unreflective` makes the code compile, so the error only occurs when the annotation is present.

Same issue also happens with `@:nativeGen`

# Minimal reproducible example
```haxe
package;

@:unreflective
class Main {
public static function main():Void {
addEventListener("aaa", method);
}

public static function method(a:String):Void {
trace(a);
}

public static function addEventListener(type:String, listener:T->Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void
{
trace(type, listener, useCapture, priority, useWeakReference);
}
}
```

# Compilation output
```ex
Error: Main.cpp
./src/Main.cpp(34): error C2039: 'method_dyn': is not a member of 'Main_obj'
include\Main.h(13): note: see declaration of 'Main_obj'
./src/Main.cpp(34): error C3861: 'method_dyn': identifier not found
```

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.