This would allow patterns like function($x) {return $x;} to be recognised as <T> (T) -> T rather than (mixed) -> mixed.
A possible approach to this may be to track the origin of a "mixed" expression and, where its origin is the current called entity, infer the return type from the appropriate arg; however it'll be better to actually express it as a generic type so that the call types can produce a synthesised function type and continue that way. Generics for return types are unlikely given the lack of strong typing, but those are considerably less useful in general.
This would allow patterns like
function($x) {return $x;}
to be recognised as<T> (T) -> T
rather than(mixed) -> mixed
.A possible approach to this may be to track the origin of a "mixed" expression and, where its origin is the current called entity, infer the return type from the appropriate arg; however it'll be better to actually express it as a generic type so that the call types can produce a synthesised function type and continue that way. Generics for return types are unlikely given the lack of strong typing, but those are considerably less useful in general.