Skip to content

Breaking changes in Haxe 5.0.0

Simon Krajewski edited this page Feb 2, 2024 · 4 revisions

bind typing with optional arguments

Haxe 4 hides trailing optional arguments when using bind on a function:

function f(notOpt:Int, ?opt:String) {}

function main() {
	var fBind = f.bind(1);
	$type(fBind); // () -> Void
}

In Haxe 5, this is now typed as (?opt : Null<String>) -> Void which might cause unification errors. The easiest way to address this is to use explicit _ for all trailing optional arguments:

function f(notOpt:Int, ?opt:String) {}

function main() {
	var fBind = f.bind(1, _);
	$type(fBind); // (?opt : Null<String>) -> Void
}

This works in both Haxe 4 and 5.