HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

Generics regression #11618

Closed kLabz closed 3 months ago

kLabz commented 3 months ago

This is failing since 3c07ce1569df6daf03a4fa4a8ab520af5273759a

using Main;

function main() {}

class Extensions {
    @:generic
    public static function pickMapWeight<T>(map: Map<T, Float>, ?eltCount : Int) : T {
        var arr = map.keys().toArray();
        if (eltCount != null && arr.length <= eltCount)
            return arr.pickWeight();

        return arr.pickWeight();
    }

    @:generic
    public static function pickWeight<T>(array: Array<T>) : T {
        if (array.length == 0) return null;
        return array[0];
    }

    inline public static function toArray<T>(it: Iterator<T>) {
        return [for(a in it) a];
    }
}

With

src/Main.hx:12: characters 10-26 : error: pickMapWeight.T should be pickMapWeight.T
src/Main.hx:12: characters 10-26 : ... have: (...) -> pickMapWeight.T
src/Main.hx:12: characters 10-26 : ... want: (...) -> pickMapWeight.T
src/Main.hx:12: characters 10-26 : Cannot create field pickWeight_pickMapWeight_T due to type mismatch
src/Main.hx:16: lines 16-19 : ... Conflicting field was defined here
yuxiaomao commented 3 months ago

same as https://github.com/HaxeFoundation/haxe/issues/11608 (I believe we found it in the same code base)

kLabz commented 3 months ago

Ah yeah I forgot about that issue :sweat_smile: