HaxeFoundation/hashlink

'Can't cast (void (ref<f64>)) to (void ())' error for methods with varargs parameters

Poobslag opened this issue · 3 comments

image

HashLink complains that it Can't cast (void (ref<f64>)) to (void ()) when passing an FlxButton.callback parameter into a method that takes a Void->Void, despite FlxButton defining callback as a Void->Void itself.

Here are the results of a haxelib list, to clarify which versions are in use

actuate: 1.8.9 [1.9.0]
box2d: [1.2.3]
flixel-addons: 2.9.0 2.10.0 2.11.0 [3.1.1]
flixel-demos: 2.7.3 2.7.4 2.8.0 [2.9.0]
flixel-templates: 2.6.5 [2.6.6]
flixel-tools: 1.4.4 [1.5.1]
flixel-ui: 2.3.3 2.4.0 [2.5.0]
flixel: 4.8.1 4.9.0 4.10.0 [5.3.1]
format: [3.5.0]
hashlink: git [dev:C:\HaxeToolkit\haxe\lib\hashlink/git/other/haxelib/]
haxelib: [4.1.0]
hscript: 2.4.0 [2.5.0]
hxcpp-debug-server: 1.2.4 [dev:c:\Users\aaron\.vscode\extensions\vshaxe.hxcpp-debugger-1.2.4\hxcpp-debug-server]
hxcpp: 4.2.1 [4.3.2]
hxp: [1.2.2]
layout: [1.2.1]
lime-samples: [7.0.0]
lime: 7.8.0 7.9.0 [8.0.1] git
openfl-samples: [8.7.0]
openfl: 9.0.2 9.1.0 [9.2.1] git
systools: [1.1.0]

Investigating further, the problem seems to only occur when the target method includes varargs, such as this method:

public function cameraRight(tweenDuration:Float = 0.3):Void

The problem can be worked around by adding an extra layer of reflection/indirection:

-var _cameraButton:FlxButton = newButton(button.image, button.x + _pokeWindow.x, button.y + _pokeWindow.y, 28, 28, button.callback);
+var _cameraButton:FlxButton = newButton(button.image, button.x + _pokeWindow.x, button.y + _pokeWindow.y, 28, 28, () -> button.callback(0.3));

Closing the issue; this is an inconsistency from other non-hashlink platforms which have no problem passing varargs functions as void functions, but I don't think it's anything that needs to be fixed.