Skip to content
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

Template Parameters + non-empty-string bug #5372

Closed
AlexandruGG opened this issue Jul 23, 2021 · 6 comments
Closed

Template Parameters + non-empty-string bug #5372

AlexandruGG opened this issue Jul 23, 2021 · 6 comments
Labels
Milestone

Comments

@AlexandruGG
Copy link

Bug report

Hello, the new 0.12.93 release seems to have introduced a bug regarding non-empty-string and string usage with template parameters.

More specifically, non-empty-string seems to not be properly treated as a subtype of string.

Code snippet that reproduces the problem

https://phpstan.org/r/8ca61235-3da9-49cc-9b61-09b51abc7ee8

Expected output

No error should be reported because it's valid to pass a non-empty-string to something that expects a string. Only the opposite is not allowed.

The same snippet in Psalm shows no error: https://psalm.dev/r/f5871a0f0b

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 23, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 26, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 26, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 26, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 26, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 26, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 26, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 27, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 27, 2021
drupol added a commit to loophp/collection that referenced this issue Jul 28, 2021
* SA: Update Scan* operations.

* SA: Add Window static analysis tests.

* SA: Add Tails static analysis tests.

* SA: Add Tail static analysis tests.

* SA: Add Pair static analysis tests.

* SA: Add Pack static analysis tests.

* SA: Add Lines static analysis tests.

* SA: Add Reduction static analysis tests.

* refactor: Update Pipe operation.

* Show some failures

* Fix some phpstan issues

* Fix Reduction based on feedback.

* Temporary workaround until phpstan/phpstan#5372 is fixed.

* Update PHPStan baseline, remove stuff.

* SA: Update Reduce operations.

* Update PHPStan baseline.

Co-authored-by: AlexandruGG <alex.gidei@goodlord.co>
@vhenzl
Copy link
Contributor

vhenzl commented Aug 8, 2021

I have a similar problem: an array with non-empty-string key can't accept non-empty-string as its key.
PHPStan reports: "Array (array<string, string>) does not accept key string."

Repro: https://phpstan.org/r/e577e855-62ef-448c-8ccf-7a2e0dda538e

@phpstan-bot
Copy link
Contributor

@AlexandruGG After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (1 error)
+PHP 8.0
 ==========
 
-32: Parameter #1 $list of function takesStrings expects Collection<int, string>, Collection<int, non-empty-string> given.
+No errors
 
-PHP 7.4 (2 errors)
+PHP 7.4 (1 error)
 ==========
 
 11: Promoted properties are supported only on PHP 8.0 and later.
-32: Parameter #1 $list of function takesStrings expects Collection<int, string>, Collection<int, non-empty-string> given.
 
 PHP 7.1 – 7.3 (3 errors)
 ==========
Full report

PHP 8.0

No errors

PHP 7.4 (1 error)

Line Error
11 Promoted properties are supported only on PHP 8.0 and later.

PHP 7.1 – 7.3 (3 errors)

Line Error
32 Syntax error, unexpected ')' on line 32
32 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 32
32 Syntax error, unexpected T_VARIABLE, expecting ')' on line 32

@ondrejmirtes
Copy link
Member

Fixed the issue from OP: phpstan/phpstan-src@6a33de9

@vhenzl Your issue is different, I improved the type verbosity to highlight the problem:

 ------ ---------------------------------------------------------------------
  Line   test.php
 ------ ---------------------------------------------------------------------
  14     Array (array<non-empty-string, string>) does not accept key string.
 ------ ---------------------------------------------------------------------

@ondrejmirtes
Copy link
Member

@vhenzl Fixed your problem too: phpstan/phpstan-src@7172e5f

@AlexandruGG
Copy link
Author

@ondrejmirtes thank you for fixing this!

drupol added a commit to loophp/collection that referenced this issue Aug 21, 2021
drupol added a commit to loophp/collection that referenced this issue Aug 22, 2021
* fix: Fix constant type typo.

* chore: Update PSalm baseline now that phpstan/phpstan#5372 has been fixed and released.

* fix: Update SA tests accordingly.
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants