Skip to content

Typed callable when mixed used#2986

Merged
TomasVotruba merged 1 commit intorectorphp:masterfrom
snapshotpl:typed-callable
Apr 14, 2020
Merged

Typed callable when mixed used#2986
TomasVotruba merged 1 commit intorectorphp:masterfrom
snapshotpl:typed-callable

Conversation

@snapshotpl
Copy link
Copy Markdown
Contributor

Covers #2881 and #2884

@@ -1 +1 @@
/** @var callable(array<mixed>) */
/** @var callable(array<mixed>):mixed */
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.

Please keep these 2 and add 2 new extra files, so it's clear there is no change in behavior

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.

But this behavior it's what we need. We need to disallow typed callable without return type via phpstan/phpstan#3008

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.

How would you explain people a rule that changes their phpdocs?

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.

IMO mixed means same no return type. So this change just improve callable definition.

Currently rector changes my phpdocs by remove mixed, so who would you explain me this change ;-)

Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba Mar 3, 2020

Choose a reason for hiding this comment

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

That's just moving problem from to right. Soon someone will send the revert PR :)

The solution is to respect both cases.

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.

@ondrejmirtes maybe you can add something to discussion? Your voice is important because currently this trigger error in phpstan phpstan/phpstan#3008

Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba Mar 5, 2020

Choose a reason for hiding this comment

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

@snapshotpl Probably. I have focused on many other issues since.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

callable(X) without return typehint in PHPDoc was never supported, because it's ambiguous for the AST parser. Better to use the callable(X): mixed syntax.

Is it IdentifierTypeNode with (X) description, or is it CallableTypeNode? There's no way to tell. I added some tests with the current behaviour based on the issue phpstan/phpdoc-parser@e2b89c5

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.

@TomasVotruba what are you thing now?

This change is introduced by my request, so probably nobody cares about "revert" this behavior.

If it's BC break you can start with 0.8, but IMO callable, if typed, should always contains return type.

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.

Format must be preserved. It's the most discouraging to see no change yet 200 changed files

@snapshotpl
Copy link
Copy Markdown
Contributor Author

@TomasVotruba which rector should I disable to prevent this change?

@TomasVotruba
Copy link
Copy Markdown
Member

That's not possible, It's part of the printer.

@snapshotpl
Copy link
Copy Markdown
Contributor Author

So I'm blocked to 0.7 upgrade...

@TomasVotruba
Copy link
Copy Markdown
Member

Until it's fixed, yes

@snapshotpl
Copy link
Copy Markdown
Contributor Author

Any plan to move it forward? IMO This change is fine, however I see you have different opinion.

@TomasVotruba
Copy link
Copy Markdown
Member

Anything that preserves format is ok

@TomasVotruba
Copy link
Copy Markdown
Member

On second thought, let's give it a try and wait for community feedback.

Thank you for your work 👍

@TomasVotruba TomasVotruba merged commit 4b00250 into rectorphp:master Apr 14, 2020
@snapshotpl
Copy link
Copy Markdown
Contributor Author

🍻

TomasVotruba added a commit that referenced this pull request Oct 14, 2022
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