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
Type information lost during array key affectation ? #4165
Comments
Yeah, it's a bug :) I'd start by removing the generalization from here https://github.com/phpstan/phpstan-src/blob/0e3230199e5282639bc50500286bc8244ff8a748/src/Type/Constant/ConstantArrayTypeBuilder.php#L101, it might make some tests fail, but it will probably fix this issue. |
I guess a similar thing happens there: https://phpstan.org/r/9e3f4300-ee94-4f03-98cf-cc5cfa329f15 PHPStan starts treating int as int|string |
@binary-data This is completely different, please open a separate issue about that. |
Opened a new issue: #4612 |
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>&nonEmpty. Full report
|
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<non-empty-string, 3|4|5|42>&nonEmpty. Full report
|
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<literal-string&non-empty-string, 3|4|5|42>&nonEmpty. Full report
|
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<literal-string&non-empty-string, 3|4|5|42>&nonEmpty. Full report
|
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<literal-string&non-empty-string, 3|4|5|42>&nonEmpty. Full report
|
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns non-empty-array<literal-string&non-empty-string, 3|4|5|42>. Full report
|
@greg0ire After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-33: Method ComparisonKeysBuilder::__invoke() should return array<'int'|'prd'|'stg', int> but returns array<string, 3|4|5|42>.
+No errors |
Closes phpstan/phpstan#4906 Closes phpstan/phpstan#4165 Closes phpstan/phpstan#4910 Closes phpstan/phpstan#3703
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report / Feature Request? I'm not sure…
It seems that under some conditions, PHPStan generalizes a "finite" (not sure what the right term is) type to an "infinite" one.
Code snippet that reproduces the problem
https://phpstan.org/r/1d06b068-483f-483e-a0cf-ef0ff3a29ade
Expected output
No errors.
The text was updated successfully, but these errors were encountered: