No longer verify types, when TypeSpecifyingExtension uses $overwrite=true#1011
Merged
ondrejmirtes merged 5 commits intophpstan:masterfrom Feb 11, 2022
Merged
No longer verify types, when TypeSpecifyingExtension uses $overwrite=true#1011ondrejmirtes merged 5 commits intophpstan:masterfrom
ondrejmirtes merged 5 commits intophpstan:masterfrom
Conversation
| TypeSpecifierContext $context | ||
| ): SpecifiedTypes | ||
| { | ||
| $newType = new GenericObjectType(\GenericTypeOverride\Foo::class, [\GenericTypeOverride\Bar::class]); |
Member
There was a problem hiding this comment.
This isn't how the constructor should be called. The constructor looks like this:
/**
* @api
* @param array<int, Type> $types
*/
public function __construct(
string $mainType,
private array $types,
?Type $subtractedType = null,
private ?ClassReflection $classReflection = null,
)
You need new ObjectType(\GenericTypeOverride\Bar::class) instead.
Contributor
Author
There was a problem hiding this comment.
thx for catching. with this fix, the unit test works like expected:
$ vendor/bin/phpunit tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeGenericOverwriteRuleTest.php
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
PHPUnit 9.5.7 by Sebastian Bergmann and contributors.
Warning: XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set
F 1 / 1 (100%)
Time: 00:00.424, Memory: 52.00 MB
There was 1 failure:
1) PHPStan\Rules\Comparison\ImpossibleCheckTypeGenericOverwriteRuleTest::testNoReportedErrorOnOverwrite
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'
+'13: Call to method GenericTypeOverride\Foo<int>::setFetchMode() will always evaluate to false.
'
C:\dvl\Workspace\phpstan-src-staabm\src\Testing\RuleTestCase.php:140
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Rules\Comparison\ImpossibleCheckTypeGenericOverwriteRuleTest.php:34
I am wondering whether phpstan should have errored about this when scanning the test-case?
as can be seen in the github actions, it did not catch this problem
Contributor
|
I wonder if this is related or will fix cases over on webmozart-assert too. Need to check later :) |
|
|
||
| public function testNoReportedErrorOnOverwrite(): void | ||
| { | ||
| $this->treatPhpDocTypesAsCertain = false; |
Member
There was a problem hiding this comment.
This doesn't need to be a property if you're not testing true/false scenarios. So please put "true" directly in the constructor.
Member
|
Thank you. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes phpstan/phpstan#6620
I am not 100% happy with the test-case.
the test fails without the fix and passes with it - as expected.
but when running the test without the fix I get this error:
it seems there is something missing which makes the test end properly (without the fix), to render a proper repro-case.
the test errors here
phpstan-src/src/Rules/Comparison/ImpossibleCheckTypeHelper.php
Line 195 in 4f72fdc
because it seems it cannot find some part of the involved objects within
$scope- I guess.