Skip to content
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

Forbid @template annotation on closures #5472

Closed
weirdan opened this issue Mar 24, 2021 · 2 comments · Fixed by #5499
Closed

Forbid @template annotation on closures #5472

weirdan opened this issue Mar 24, 2021 · 2 comments · Fixed by #5499

Comments

@weirdan
Copy link
Collaborator

weirdan commented Mar 24, 2021

Hack doesn't support templated closures, and I don't think there's much value in Psalm supporting them either. Opens up a whole can of worms.

Originally posted by @muglug in #5471 (comment)

It's currently accepted, but does not produce a useful generic: https://psalm.dev/r/93bb04856b. It would be better to reject it outright.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/93bb04856b
<?php
$f = 
/**
 * @template T
 * @param T $t
 * @return T
 */
 fn($t) => $t;

$f(42);
Psalm output (using commit 2edf613):

ERROR: InvalidArgument - 10:4 - Argument 1 expects T:fn-/var/www/vhosts/psalm.dev/httpdocs/src/somefile.php:8:64:-:closure as mixed, 42 provided

@weirdan
Copy link
Collaborator Author

weirdan commented Mar 24, 2021

Expected: InvalidDocblock: Templated closures are not supported

weirdan added a commit to weirdan/psalm that referenced this issue Mar 29, 2021
They don't work properly anyway.

Fixes vimeo#5472
weirdan added a commit to weirdan/psalm that referenced this issue Mar 29, 2021
They don't work properly anyway.

Fixes vimeo#5472
muglug pushed a commit that referenced this issue Mar 29, 2021
They don't work properly anyway.

Fixes #5472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant