Skip to content

Conversation

@rvanvelzen
Copy link
Contributor

Fix #151

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Every parser change now has implications for the Printer.

This change now means that the return type can contain NullableTypeNode which has to be parenthesized.

This change should be tested by trying to print CallableTypeNode with NullableTypeNode in the return type. The change needs to happen here:

if ($node->returnType instanceof CallableTypeNode || $node->returnType instanceof UnionTypeNode || $node->returnType instanceof IntersectionTypeNode) {

Also the format-preserving printer needs an addition in Printer::$parenthesesMap:

CallableTypeNode::class . '->returnType' => [
CallableTypeNode::class,
UnionTypeNode::class,
IntersectionTypeNode::class,
],

@rvanvelzen
Copy link
Contributor Author

Nullable types were already accepted, and do not need to be parenthesized. The only change is that conditional types are now accepted.

@ondrejmirtes
Copy link
Member

Oh right, I didn't realize that.

@ondrejmirtes ondrejmirtes merged commit bcad8d9 into phpstan:1.23.x Sep 26, 2023
@ondrejmirtes
Copy link
Member

Thank you!

@rvanvelzen rvanvelzen deleted the callable-conditional-return-type branch September 26, 2023 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants