Skip to content

Added DynamicReturnTypeExtension for trigger_error#766

Merged
ondrejmirtes merged 4 commits intophpstan:masterfrom
staabm:bug5992
Nov 19, 2021
Merged

Added DynamicReturnTypeExtension for trigger_error#766
ondrejmirtes merged 4 commits intophpstan:masterfrom
staabm:bug5992

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Nov 13, 2021

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Nov 13, 2021

Build errors are unrelated

@staabm
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

Account for E_USER_ERROR halting execution

3 participants