haxe icon indicating copy to clipboard operation
haxe copied to clipboard

type param constraint checks vs "const" structures

Open nadako opened this issue 8 years ago • 2 comments

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
    }
}

nadako avatar Mar 01 '17 22:03 nadako

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

Simn avatar Mar 02 '17 07:03 Simn

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?

back2dos avatar Mar 02 '17 08:03 back2dos