Skip to content

Add regression test for #11507 - #6747

Open
HawkForge wants to merge 1 commit into
phpstan:2.3.xfrom
HawkForge:test/bug-11507
Open

HawkForge wants to merge 1 commit into
phpstan:2.3.xfrom
HawkForge:test/bug-11507

Conversation

@HawkForge

@HawkForge HawkForge commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Adds a regression test for #11507, reported by @liamduckett. The reproducer from the issue (a Collection::map() callback that sets $item['foo'] on a non-empty-array<string, string>) no longer reports "Function foo() should return Collection<int, non-empty-array<string, string>> but returns Collection<int, non-empty-array<string, string>>" since the bidirectional type narrowing work landed in 2.3.x. The test fails on 2.2.17 with exactly that error and passes on 2.3.x.

Refs phpstan/phpstan#11507 (covers the first reproducer only; the simpler one from the comments still reports the error)

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one of the reproducers of the referenced issue is fixed. therefore this PR does not close the issue.


declare(strict_types = 1);

namespace Bug11507;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems this snippet was adopted and does not reflect 1:1 the reported reproducer of phpstan/phpstan#11507 (comment) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which of the snippets in the referenced issue contains this code-example. I was not able to find it. it still looks like it was adopted

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is the snippet from the opening description. Although I don't think that it passes yet anyway. I suspect (haven't investigated) that as a result, the test in question isn't behaving as intended?

Incase it saves anyone any time, the comment at the end of my issue reporting that 2.3.x now has a different report was for another snippet (which does now pass).

@HawkForge

Copy link
Copy Markdown
Contributor Author

Thanks @staabm, you're right. I changed Closes to Refs in the description and in the commit message, so the issue stays open for the other reproducer. The test still covers only the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants