HaxeFoundation / haxe

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

type param constraint checks vs "const" structures #6066

Open nadako opened 7 years ago

nadako commented 7 years ago

Shouldn't the second call also work?

typedef S = {a:Int, ?b:Int};

class Main {
    static function f1(a:S):Void {}
    static function f2<T:S>(a:T):Void {}

    static function main() {
        f1({a: 1}); // works
        f2({a: 1}); // Constraint check failure: { a : Int } should be { ?b : Null<Int>, a : Int }
        f2(({a: 1} : S)); // works
    }
}
Simn commented 7 years ago

Maybe, I don't know... ask @ousado!

back2dos commented 7 years ago

My guess is that the type of {a : 1} is closed before it is checked against the constraint. Maybe because it is first unified with f2.T which closes it and then checked?