Skip to content

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

@jtopenpetition

Description

@jtopenpetition

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions