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

Added DynamicReturnTypeExtension for trigger_error #766

Merged
merged 4 commits into from
Nov 19, 2021

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 13, 2021

@staabm
Copy link
Contributor Author

staabm commented Nov 13, 2021

Build errors are unrelated

@staabm
Copy link
Contributor Author

staabm commented Nov 18, 2021

rebased against master. all green now.

$errorType = $scope->getType($functionCall->getArgs()[1]->value);
if ($errorType instanceof ConstantScalarType) {
if ($errorType->getValue() === E_USER_ERROR) {
return new NeverType();
Copy link
Member

Choose a reason for hiding this comment

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

We should also test that this behaves as an actual terminating call. Try this:

function foo(?string $s): void
{
    if ($s === null) {
        trigger_error('foo', E_USER_ERROR);
    }
    assertType('string', $s);
}

Copy link
Contributor Author

@staabm staabm Nov 19, 2021

Choose a reason for hiding this comment

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

hmm interessting.. you are right, this case is failling atm.

I had the impression that phpstan would handle a NeverType returned from a DynamicFunctionReturnTypeExtension automatically as a terminating call. wouldn't that make sense, instead of adding such logic case by case?

Copy link
Member

Choose a reason for hiding this comment

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

You need return new NeverType(true);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

already fixed :-). thx.

@ondrejmirtes ondrejmirtes merged commit 746b9b5 into phpstan:master Nov 19, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the bug5992 branch April 4, 2022 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants