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

allow dismissing return value of no-return pure functions #5461

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

azjezz
Copy link
Contributor

@azjezz azjezz commented Mar 23, 2021

refs azjezz/psl#163

no-return function either:

  1. exit
  2. throw exceptions
  3. run forever

in all of these cases, it's okay not to use the return value.

@weirdan
Copy link
Collaborator

weirdan commented Mar 23, 2021

And you want to keep such functions pure to be able to call them in pure contexts, right?

@azjezz
Copy link
Contributor Author

azjezz commented Mar 23, 2021

yes,

example:


currently to avoid this i suppressed all UnusedFunctionCall ( https://github.com/azjezz/psl/blob/1.6.x/psalm.xml#L65 ), but i don't really want to do that


also relevant: also relevant: azjezz/psl#163 (comment)

@azjezz
Copy link
Contributor Author

azjezz commented Mar 23, 2021

build failure is unrelated.

@muglug muglug merged commit 477ae33 into vimeo:master Mar 23, 2021
@muglug
Copy link
Collaborator

muglug commented Mar 23, 2021

I think this is exactly the right approach, thanks!

While traditionally throwing an exception might be considered a side-effect, I think Psalm's notion of purity is safe enough

@azjezz azjezz deleted the pure-unused branch March 23, 2021 23:34
!(
$function_call_info->function_storage &&
$function_call_info->function_storage->return_type &&
(array_values($function_call_info->function_storage->return_type->getAtomicTypes())[0] ?? null) instanceof Type\Atomic\TNever
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced this with $function_call_info->function_storage->return_type->isNever()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't notice the method existed 😅

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 this pull request may close these issues.

3 participants