Repository navigation
reproduce specifier bug #1396
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
Closed
Closed
reproduce specifier bug #1396
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug1396; | ||
|
|
||
| use PHPStan\Type\Constant\ConstantStringType; | ||
| use PHPStan\Type\ConstantScalarType; | ||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| class HelloWorld | ||
| { | ||
| public function doFoo( | ||
| ConstantScalarType $constantType | ||
| ): SpecifiedTypes | ||
| { | ||
| assertType('bool|float|int|string|null', $constantType->getValue()); | ||
|
|
||
| if ($constantType->getValue() === null) { | ||
| return new SpecifiedTypes(); | ||
| } | ||
|
|
||
| assertType('bool|float|int|string', $constantType->getValue()); | ||
|
|
||
| if ( | ||
| $constantType instanceof ConstantStringType | ||
| ) { | ||
| assertType('string', $constantType->getValue()); | ||
| } | ||
| assertType('bool|float|int|string', $constantType->getValue()); | ||
| } | ||
| } | ||
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.
it seems this nullcheck is somehow messing it up
maybe @rvanvelzen has an idea?
Uh oh!
There was an error while loading. Please reload this page.
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.
That's interesting. Null isn't even a scalar, right? Is this ever triggered and is there even a ConstantType that implements returning null via getValue?nevermind NullType implements this of course..Might be unrelated to the bug though.. 😅
Uh oh!
There was an error while loading. Please reload this page.
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.
Ah one more thing came to mind: could it be related to the fact that phpstan remembers what the method returned? Maybe this needs to he invalidated below in the if scope.
The bug might then be that method return types are falsely remembered / not invalidated, even if the class instance changes. Or smth like that
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.
@rajyan do you have an idea on how to approach this problem? maybe you even have time for a fix?
Uh oh!
There was an error while loading. Please reload this page.
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.
https://phpstan.org/r/a7200b8c-8482-4fd2-b782-ecdb8052a28a
This bug looks very interesting, the commented out line changes the result. Rough guess, the type specification with instanceof is not working or moreSpecificType
$var->getValue()remembered by !== null is breaking something.I don’t have time this week (and this weekend) but I think I can fix it next week.
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.
Another guess is that the moreSpecificType is not correctly invalidated correctly on type specification by instanceof.