New inference: improved error message for unresolved type
Summary:
When Hack can't resolve a type for operations such as method invocation, it currently points the finger of blame at the use of a generic function or constructor that introduced the type variable. But often it's better to point the blame at an unannotated lambda. For example, with
```
function just_return_it<T>((function(T):void) $f):(function(T):void) { return $f; }
function break_it(string $ss):void {
$g1 = just_return_it($y ==> $y->this_method_does_not_exist());
$g2 = just_return_it($y ==> { $z = $y; $z->this_method_also_does_not_exist(); });
$g1("hahahaha");
}
```
Instead of
```
Typing[4297] Was expecting an object but type is unknown
--> lambda_tyvar.php
4 | function just_return_it<T>((function(T):void) $f):(function(T):void) { return $f; }
| ^ via this generic T
7 | $g1 = just_return_it($y ==> $y->this_method_does_not_exist());
| ^^
| ^^^^^^^^^^^^^^ It is unknown because type parameter T of just_return_it could not be determined. Please add type parameters to just_return_it.
Typing[4297] Was expecting an object but type is unknown
--> lambda_tyvar.php
4 | function just_return_it<T>((function(T):void) $f):(function(T):void) { return $f; }
| ^ via this generic T
8 | $g2 = just_return_it($y ==> { $z = $y; $z->this_method_also_does_not_exist(); });
| ^^
| ^^^^^^^^^^^^^^ It is unknown because type parameter T of just_return_it could not be determined. Please add type parameters to just_return_it.
```
we can produce the more useful
```
Typing[4297] Was expecting an object but type is unknown
--> lambda_tyvar.php
7 | $g1 = just_return_it($y ==> $y->this_method_does_not_exist());
| ^^
| ^^ It is unknown because type of lambda parameter could not be determined. Please add type hint to parameter
Typing[4297] Was expecting an object but type is unknown
--> lambda_tyvar.php
8 | $g2 = just_return_it($y ==> { $z = $y; $z->this_method_also_does_not_exist(); });
| ^^
| ^^ It is unknown because type of lambda parameter could not be determined. Please add type hint to parameter
```
Also slightly improved the original message about type parameters.
Reviewed By: DavidSnider
Differential Revision:
D15335592
fbshipit-source-id:
d93cc1de7a951215339fb3c9f54179719997bac4