HaxeFoundation / haxe

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

@:generic compilation error when the function is called multiple times #11608

Closed yuxiaomao closed 6 months ago

yuxiaomao commented 6 months ago

I discovered that the following code does not compile anymore. I don't know how exactly @:generic should work, but it looks very strange that the first call to doF does not yield any error, but the followings call failed with a message that does not make much sense. First bad commit https://github.com/HaxeFoundation/haxe/commit/3c07ce1569df6daf03a4fa4a8ab520af5273759a.

using Test.ArrayExtension;
class Test {
    public static function doF2<T>(f: T -> Float) : T {
        var arr = [];
        arr.doF(f); // Ok
        arr.doF(f); // error: doF2.T should be doF2.T Cannot create field doF_doF2_T due to type mismatch
        return arr.doF(f); // error: doF2.T should be doF2.T Cannot create field doF_doF2_T due to type mismatch
    }

    static public function main() {
    }
}

class ArrayExtension {
    @:generic
    public static function doF<T>(array: Array<T>, f: T -> Float) : T {
        return null;
    }   
}