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

Introduce InvalidTypesInUnionRule #2763

Merged
merged 1 commit into from Nov 22, 2023

Conversation

paulbalandan
Copy link
Contributor

@ondrejmirtes ondrejmirtes merged commit c6898a1 into phpstan:1.10.x Nov 22, 2023
425 checks passed
@ondrejmirtes
Copy link
Member

I love it, thank you very much!

@herndlm
Copy link
Contributor

herndlm commented Nov 22, 2023

Nice, thx @paulbalandan !


namespace InvalidUnionWithMixed;

class Foo
Copy link
Contributor

Choose a reason for hiding this comment

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

what about applying the same rules for phpdoc types?

https://phpstan.org/r/9c3d8fed-52b9-4285-b877-c34ec751ae4c

Copy link
Member

Choose a reason for hiding this comment

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

We'd have to give it some more thought, thanks to type normalization mixed|null is totally fine in PHPDocs, I don't want to mark that as an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

a special rule only for phpdocs invalid types maybe, maybe hidden behind bleeding edge? hmm

Copy link
Member

Choose a reason for hiding this comment

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

Invalid types in PHPDocs like string&int are already reported. If you think there is some scenario that isn't covered, open a new feature requests, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned before, we have phpstan/phpstan#6720 already, so it might be a special thing for void mostly :)

Copy link
Member

Choose a reason for hiding this comment

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

Void in return types should be transformed into null after a call.

Copy link
Contributor

Choose a reason for hiding this comment

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

would you say only for phpdoc or in general? currently thinking were the best place is to transform types 🤔

Copy link
Member

Choose a reason for hiding this comment

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

In MutatingScope::resolveType where MethodCall/StaticCall/FuncCall are handled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok thx, I did exactly that already 😊 looked mostly good with a couple of question marks. Will open a PR when ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants