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
Improve in_array
assertion to extract assertions for non-literal types
#6233
Conversation
4812085
to
81737a9
Compare
Extract non-literal type assertion from in_array Extract false, true and null assertion Fix assertion against arrays with union-typed values Fix assertion against non-sealed arrays
81737a9
to
097e88a
Compare
The last commit fixes 2 old tests, which used to pass before because By looking at those tests I believe that original intention was to check against a known and fixed list of constants, which is So I wouldn't call it a regression, it's a bug fix rather. |
src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php
Outdated
Show resolved
Hide resolved
Indeed, |
Seems awesome! Thanks :) |
9dbb0b6
to
02324a1
Compare
|
02324a1
to
c0aac96
Compare
c0aac96
to
65a129e
Compare
@supersmile2009 seems like something broke in Psalm. Can you check it? |
@orklah done. Could you trigger the CI again? |
and simplified the code a bit.
Thanks! |
This triggered a new false positive in my work codebase: https://psalm.dev/r/aaa65f492c |
I found these snippets: https://psalm.dev/r/aaa65f492c<?php
class A{
public static array $array1 = ['a', 'b'];
public static array $array2 = ['c', 'd'];
}
$element = 'element2';
if(in_array($element, A::$array1, true)) {
$_a = 1;
} elseif(in_array($element, A::$array2, true)) {
$_a = 2;
}
|
Fixes #6220
Thanks @orklah for the tip on where to check.