extern overloads
Heya,
There are some externs that I'm using that make use of the "overload" functionality provided in Haxe. Currently this is not supported.
class Test {
public extern inline overload function test(a: String): Void {
trace("a string");
}
public extern inline overload function test(a: Int): Void {
trace("an int");
}
public extern inline overload function test(a: Int, b: String): Void {
trace("both!");
}
public function new() {
test("Hello");
test(42);
test(42, "Hello");
}
}
In this example I'm using inline to demo it with purely Haxe code (makes testing easier).
Luckily, I started implementing this today and was just creating an issue when I saw this :)
not sure i understand the issue, what is the problem that needs fixing ?
not sure i understand the issue, what is the problem that needs fixing ?
This feature is similar to Java's function feature, we can create functions with the same name and different parameters.
The IDE only accepts the first one and gives a type issue highlight.
Heya,
There are some externs that I'm using that make use of the "overload" functionality provided in Haxe. Currently this is not supported.
class Test { public extern inline overload function test(a: String): Void { trace("a string"); }
public extern inline overload function test(a: Int): Void { trace("an int"); } public extern inline overload function test(a: Int, b: String): Void { trace("both!"); } public function new() { test("Hello"); test(42); test(42, "Hello"); }} In this example I'm using
inlineto demo it with purely Haxe code (makes testing easier).
Oh, i can't reproduce issue with your sample.
Let me prepare a new example.
this is how it looks to me when trying to test with return types
Okay here is new reproduce code
class Test {
public function new() {
Test2.test("Hello");
Test2.test(42);
Test2.test(42, "Hello");
}
}
class Test2 {
public overload extern inline static function test(a: String): Void {
trace("a string");
}
public overload extern inline static function test(a: Int): Void {
trace("an int");
}
public overload extern inline static function test(a: Int, b: String): Void {
trace("both!");
}
}
ah ok, so the issue is static member overloads then.
ah ok, so the issue is static member overloads then.
No, the problem does not only occur in internal access.
class Test {
public function new() {
var test2 = new Test2();
test2.test("Hello");
test2.test(42);
test2.test(42, "Hello");
}
}
class Test2 {
public overload extern inline function test(a: String): Void {
trace("a string");
}
public overload extern inline function test(a: Int): Void {
trace("an int");
}
public overload extern inline function test(a: Int, b: String): Void {
trace("both!");
}
}
i have made a beta build that support some overload usage, it would be helpful if you tested it and let me know if it fixes your issues.
https://github.com/HaxeFoundation/intellij-haxe/releases/tag/pre-release%2F202506162026
i have made a beta build that support some overload usage, it would be helpful if you tested it and let me know if it fixes your issues.
https://github.com/HaxeFoundation/intellij-haxe/releases/tag/pre-release%2F202506162026
Looks fixed.
Seems to function as it should now 😎
Heya, I did find a small bug. Currently it seems like extern (inline) overloads don't work on constructors.
class MyClass {
public inline extern overload function new(a: Int) {}
public inline extern overload function new(a: Int, b: String) {}
}
class Test {
static function main() {
var a = new MyClass(1);
var b = new MyClass(1, "test");
}
}
here is a sample, this gives:
on the variable declaration of "b"
i don't think that trick is allowed on constructors, so the error seems correct, but the declaration should probably show an error
https://try.haxe.org/#4D23379B
[ERROR] Test.hx:8: characters 26-34
8 | public inline extern overload function new(a: Int) {}
| ^^^^^^^^
| Invalid modifier: overload on constructor
[ERROR] Test.hx:9: characters 26-34
9 | public inline extern overload function new(a: Int, b: String) {}
| ^^^^^^^^
| Invalid modifier: overload on constructor
[ERROR] Test.hx:9: characters 5-69
9 | public inline extern overload function new(a: Int, b: String) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Duplicate constructor
[ERROR] Test.hx:4: characters 32-38
4 | var b = new MyClass(1, "test");
| ^^^^^^
| Too many arguments
Hmm, it does seem valid on an abstract though... This is very odd behaviour.
https://try.haxe.org/#F746A3E1
I wrote up the above minimal example as a demo, didn't think it being a class or abstract would change the behaviour
I have added support for this in dev now, should be part of next release
Awesome!