-
Notifications
You must be signed in to change notification settings - Fork 530
Support "true" pseudotypes in native unions #1539
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
34a79b6
Support "true" pseudotypes in native unions
staabm d8fe9a4
fix test
staabm 253ecfe
tests
staabm b70f2a0
test
staabm 94401d6
tests
staabm 192571d
impl
staabm c50092c
fix
staabm 4e79709
tests
staabm cf9d6b4
Update ParserNodeTypeToPHPStanType.php
staabm 5191210
fix
staabm 0613181
fix path
staabm 9a23fb3
added NodeScopeResolverTest assertions
staabm db7ed21
more asserts
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php // lint >= 8.2 | ||
|
||
namespace NativeTrueType; | ||
|
||
function alwaysTrue(): true | ||
{ | ||
return true; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php // lint >= 8.2 | ||
|
||
namespace NativeTrueType; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Truthy { | ||
public true $truthy = true; | ||
|
||
public function foo(true $v): true { | ||
assertType('true', $v); | ||
} | ||
|
||
function trueUnion(true|null $trueUnion): void | ||
{ | ||
assertType('true|null', $trueUnion); | ||
|
||
if (is_null($trueUnion)) { | ||
assertType('null', $trueUnion); | ||
return; | ||
} | ||
|
||
if (is_bool($trueUnion)) { | ||
assertType('true', $trueUnion); | ||
return; | ||
} | ||
|
||
assertType('*NEVER*', $trueUnion); | ||
} | ||
|
||
function trueUnionReturn(): true|null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
if (rand(1, 0)) { | ||
return true; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
function foo(Truthy $truthy) { | ||
assertType('true', $truthy->truthy); | ||
assertType('true', $truthy->foo(true)); | ||
assertType('true|null', $truthy->trueUnionReturn()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
andIdentifier
dependent on PHP version.