Skip to content

Support "true" pseudotypes in native unions#1539

Merged
ondrejmirtes merged 13 commits intophpstan:1.8.xfrom
staabm:true-type
Sep 4, 2022
Merged

Support "true" pseudotypes in native unions#1539
ondrejmirtes merged 13 commits intophpstan:1.8.xfrom
staabm:true-type

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Jul 22, 2022

Copy link
Copy Markdown
Contributor Author

@staabm staabm left a comment

Choose a reason for hiding this comment

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

requires integration of Roave/BetterReflection#1152 into ondrejmirtes/BetterReflection to proceed

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.

initially I had the idea to make the new type only available on php 8.2+, but it seems atm we cannot do it in a version dependent way.

maybe this would even be more like a linter task.. leave it like this for now, as I realized thats the way we implemented such types in the past

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.

Allegedly this is gonna be solved in PHP-Parser 5.0 which is gonna make a thick line between Name and Identifier dependent on PHP version.

@ondrejmirtes
Copy link
Copy Markdown
Member

BetterReflection is updated in 1.8.x.

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Aug 24, 2022

did some local debugging. the last remainig part is a new PhpParser release, because in the current stable release the true type is not yet listed in the builtin-types

https://github.com/nikic/PHP-Parser/blob/34bea19b6e03d8153165d8f30bba4c3be86184c1/lib/PhpParser/ParserAbstract.php#L655-L667

on the master branch the necessary stuff is already implemented though

https://github.com/nikic/PHP-Parser/blob/0201a7ee3f86c856eb009e1393fdd654b9667684/lib/PhpParser/PhpVersion.php#L13-L26

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Sep 4, 2022

php-parser was updated with #1690

@staabm staabm marked this pull request as ready for review September 4, 2022 07:08
{
}

function trueUnionReturn(): true|null
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 are the other two methods tested? I'd expect more assertType calls here.

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.

done

@ondrejmirtes ondrejmirtes merged commit 9ceccdb into phpstan:1.8.x Sep 4, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@staabm staabm deleted the true-type branch September 4, 2022 15:30
@ondrejmirtes
Copy link
Copy Markdown
Member

@staabm Can you please also write some tests for these? Thank you! https://php.watch/versions/8.2/null-false-types

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Sep 6, 2022

Can you please also write some tests for these?

https://phpstan.org/r/1401ac97-4f3d-4209-a6bf-e3e24e621738
https://3v4l.org/PuiNS

do you mean creating new rules which emit errors in 8 <= php version < 8.2 for the linked cases?

@ondrejmirtes
Copy link
Copy Markdown
Member

No, just type inference tests to see that these standalone types work.

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.

2 participants