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

treatPhpDocTypesAsCertain: false doesn't work for nested types? #4099

Closed
jtopenpetition opened this issue Nov 19, 2020 · 2 comments
Closed
Labels

Comments

@jtopenpetition
Copy link

jtopenpetition commented Nov 19, 2020

Bug report

treatPhpDocTypesAsCertain: false apparently only works for the first level of param type hints,

the following code-snippet produces an error message for the second if clause, since it is assumed to be always false (i.e. array_key_exists is always true). for libraries that's not true.

Code snippet that reproduces the problem

<?php

/**
 * @param array{key: array{inner: mixed}} $arr
 */
function arrayHint(array $arr): void 
{
    // this respects treatPhpDocTypesAsCertain: false
    if (!array_key_exists('key', $arr)) { 
        throw new \Exception('no key "key" found.');
    }
    // this DOES NOT respect treatPhpDocTypesAsCertain: false
    if (!array_key_exists('inner', $arr['key'])) {
        throw new \Exception('need key.inner');
    }
}

https://phpstan.org/r/5d56ccbf-0ad7-4390-8077-c68d30a10af7

Expected output

nothing.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@a9ec174

@github-actions
Copy link

github-actions bot commented May 7, 2021

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 7, 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

2 participants