Function type unification problem

I suspect the question had already discussed, nevertheless I want to ask why exact parameter type( not “is type”) is required for function type unification. For example, this code doesn’t compile:

class Test 
{
    static function main() 
    {
        var f:  A  -> Void = foo;
    }
            
    static function foo(arg: B)
    {
        trace("foo called");
    }
}

class A 
{
}

class B extends A
{
}

What’s the elegant solving of this problem except creating a local var with a casting to the descendant type?

You can’t because of this:

class Test 
{
    static function main() 
    {
        var f:  A  -> Void = foo;
        f(new C()); //what?! foo does not accept C!
    }
            
    static function foo(arg: B)
    {
        trace("foo called");
    }
}

class A {}

class B extends A {}

class C extends A {}

It’s variance in action.

I see. Thank you for reply)