You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To make function result types inference more predictable and controllable, we'll try to restrict it.
New function result type inference rules:
If @return annotation exists, use that.
Otherwise use return type hint.
If neither present, infer actually returned types.
// @return is present, f1() -> int[]/** @return int[] */functionf1(): array { ... }
// type hint is present, f2() -> mixed[]functionf2(): array { ... }
// type info is infered from actual results, f3() => int[]functionf3() { return [1, 2]; }
If we've used @return or a type hint, we need to perform a typecheckReturn
and verify that actually returned values do not contradict stated types.
Instead of doing a full value (and types) analysis for typecheckReturn, it's
proposed to perform a set of checks that detect only critical issues.
This set can be extended as we adopt this approach. At some point,
we may switch to a full types analysis and handle it as PHP would.
Examples of the critical issues we should report in typecheckReturn:
It's also possible to check interface-returned types and whether
one class may be returned in place of another; see Covariance and Contravariance.
But since that's more complicated and we need to start somewhere and prepare the foundation,
let's focus on the simple things first and test it on the real projects.
Note: we should be ready to revert our changes in case this experiment is proven to be a failure.
The text was updated successfully, but these errors were encountered:
To make function result types inference more predictable and controllable, we'll try to restrict it.
New function result type inference rules:
@return
annotation exists, use that.If we've used
@return
or a type hint, we need to perform atypecheckReturn
and verify that actually returned values do not contradict stated types.
Instead of doing a full value (and types) analysis for
typecheckReturn
, it'sproposed to perform a set of checks that detect only critical issues.
This set can be extended as we adopt this approach. At some point,
we may switch to a full types analysis and handle it as PHP would.
Examples of the critical issues we should report in
typecheckReturn
:Later, we may add checks for nullability.
It's also possible to check interface-returned types and whether
one class may be returned in place of another; see Covariance and Contravariance.
But since that's more complicated and we need to start somewhere and prepare the foundation,
let's focus on the simple things first and test it on the real projects.
Note: we should be ready to revert our changes in case this experiment is proven to be a failure.
The text was updated successfully, but these errors were encountered: