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

Incorrect type for result when merging array with + operator #6965

Closed
JoyceBabu opened this issue Apr 1, 2022 · 4 comments
Closed

Incorrect type for result when merging array with + operator #6965

JoyceBabu opened this issue Apr 1, 2022 · 4 comments

Comments

@JoyceBabu
Copy link

Bug report

PHPStan is not determining the data type of resultant array when merging array with + operator, when there are values of multiple types.

Code snippet that reproduces the problem

<?php

class Test
{
    /**
     * @phpstan-var array{
     *  prop1?: int, prop2?: bool, prop3?: float,
     *  prop4?: string, prop5?: string, prop6?: string,
	 *  prop7?: string
     * }
     */
    protected array $updateData = [];

    /**
     * @phpstan-param array{
     *  prop1?: int, prop2?: bool, prop3?: float,
     *  prop4?: string, prop5?: string, prop6?: string,
	 *  prop7?: string
     * } $data
     */
    public function update(array $data): void
    {
        $this->updateData = $data + $this->updateData;
    }
}

Expected output

Does Not Work
https://phpstan.org/r/0117678d-c523-442a-8975-7ad2d03fe92c (7+ optional keys)

Works

@ondrejmirtes
Copy link
Member

I'm already working on this: phpstan/phpstan-src#1154

@JoyceBabu
Copy link
Author

I just noticed you comment on #6948 that you are already working on this :)

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#1154

@github-actions
Copy link

github-actions bot commented May 4, 2022

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 May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants