-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] Add template annotations #247
[3.x] Add template annotations #247
Conversation
c6131bf
to
e48bb63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WyriHaximus Solid progress! 👍
For context: We've had a call together with @WyriHaximus and @SimonFrings earlier today, discussing our progress for template annotations and unhandled rejections. We've discussed most of these points internally already, but figured it makes sense to post here as well for transparency.
6772ffb
to
bb7d812
Compare
f339647
to
1096398
Compare
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string { return time() % 2 ? 'string' : time(); }; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface { return resolve(time() % 2 ? 'string' : time()); }; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a) {}); $p2->then(static function (bool $a) {}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WyriHaximus Went over your changes together with @SimonFrings and addressed all outstanding issues, great work, now let's get this shipped!
@clue @SimonFrings Thank you for picking up and finishing this off and having my back in these challenging personal times ❤️ . |
@WyriHaximus No problem, we're here! Happy to support you during tough times. Take care and stay strong! |
Adds template annotations turning the
PromiseInterface
into a generic.Variables
$p1
and$p2
in the following code example both arePromiseInterface<int|string>
.When calling
then
on$p1
or$p2
, PHPStan understand that function$f1
is type hinting its parameter fine, but$f2
will throw during runtime:Builds on top of #246 and #188 and is a requirement for reactphp/async#40