Skip to content

@:overload function with param of type Array #3728

@andyli

Description

@andyli
class Test {
    @:overload static function good(v:Int):Void {}
    @:overload static function good(v:Float):Void {}
    @:overload static function bad(v:Array<Int>):Void {}
    @:overload static function bad(v:Array<Float>):Void {}
    static function main():Void {
        good(1); //no problem
        bad([1]); //Test.hx:8: characters 2-10 : Ambiguous overload
    }
}

workaround would be to manually type the argument, however...

class Test {
    @:overload static function good(v:Int):Void {}
    @:overload static function good(v:Float):Void {}
    @:overload static function bad(v:Array<Int>):Void {}
    @:overload static function bad(v:Array<Float>):Void {}
    static function main():Void {
        bad(([1]:Array<Int>));
    }
}

native compilation error:

haxelib run hxjava hxjava_build.txt --haxe-version 3200
javac "-sourcepath" "src" "-d" "obj" "-g:none" "@cmd"
src/haxe/root/Test.java:45: error: method bad(Array<Object>) is already defined in class Test
    public static void bad(haxe.root.Array<java.lang.Object> v)
                       ^
1 error
Compilation error
Native compilation failed
Error: Build failed
[Finished in 1.6s with exit code 1]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions