phpstan / phpstan-webmozart-assert

PHPStan extension for webmozart/assert
MIT License
165 stars 28 forks source link

Assert::keyExists() implemented failing unit test #41

Closed clxmstaab closed 3 years ago

clxmstaab commented 3 years ago

adds failing test for https://github.com/phpstan/phpstan-webmozart-assert/issues/39

it seems there is already some kind of keyExists handling, but it does not work yet for the added testcase

ondrejmirtes commented 3 years ago

This issue is probably totally different, it's about ConstantArrayType::accepts() behaviour in core PHPStan.

clxmstaab commented 3 years ago

This issue is probably totally different, it's about ConstantArrayType::accepts() behaviour in core PHPStan.

hmm I guess this means I am lost now. Could you give me some more pointers? or is it something very deep in the core, which a beginner will not be able to fix?

clxmstaab commented 3 years ago

I already tried to narrow it down on phpstan.org

using array_key_exists directly seem to work like expected. https://phpstan.org/r/1d951760-7d0d-47bc-bed6-429eeaa5de58

I got the impression that phpstan rewrites the ast to something like

array_key_exists('password', $data);
array_key_exists('email', $data);
a($data);

while it should be more something like

if (array_key_exists('password', $data) && array_key_exists('email', $data)) {
    a($data);
}
ondrejmirtes commented 3 years ago

If this works https://phpstan.org/r/47c28281-644a-4193-bb02-5fa61cbcb93f then this extension has to work too...

staabm commented 3 years ago

If this works https://phpstan.org/r/47c28281-644a-4193-bb02-5fa61cbcb93f then this extension has to work too...

Hmm this looks like expected to me, right?

any more pointers where the error might come from?

clxmstaab commented 3 years ago

I dont know where the difference is, but I am now able to reproduce the issue on phpstan

https://phpstan.org/r/d1f68381-095d-45c3-b89a-f9eacfa4b18b

clxmstaab commented 3 years ago

error reported upstream: https://github.com/phpstan/phpstan/issues/4560