haxe
haxe copied to clipboard
Regression with generic method overloads
The following example compiles and runs perfectly fine on versions from 4.2.0 to 4.3.6:
class Test {
static extern inline overload function foo<S:Iterable<Int>>(src:S):Int {
return src.iterator().next() + 1;
}
static extern inline overload function foo<S:Iterable<String>>(src:S):String {
return src.iterator().next() + "!";
}
static function main() {
trace(foo([12, 34, 56]));
trace(foo(["hello", "world"]));
}
}
However, on the development branch, the compilation fails:
[ERROR] Test.hx:3: lines 3-5
3 | static extern inline overload function foo<S:Iterable<Int>>(src:S):Int {
4 | return src.iterator().next() + 1;
5 | }
|
| Another overloaded field of same signature was already declared : foo
7 | static extern inline overload function foo<S:Iterable<String>>(src:S):String {
8 | return src.iterator().next() + "!";
9 | }
|
| The second field is declared here
IIRC 4.3.6 didn't properly check this, so you could have the exact same declaration as long as the type parameters had different names, or some nonsense like that.
I'm not sure what to do with this discrepancy between targets that have real overloads and those that don't. I guess this doesn't particularly matter for extern inline overloads, but it still bothers me that the rules are rather unclear.
Related commit: https://github.com/HaxeFoundation/haxe/commit/cd43c55223c08704ecdc150c26007d1213b6727f