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
Weird property purity (?) issue #7428
Comments
I found these snippets: https://psalm.dev/r/ceab5bdfcd<?php
class a {
/** @var self::STATE_* */
public int $status = self::STATE_A;
public const STATE_A = 0;
public const STATE_B = 1;
public const STATE_C = 2;
}
$a = new a;
/** @var array<string> */
$arr = [];
if (array_key_exists($a->status, $arr)) {
echo $arr[$a->status];
}
https://psalm.dev/r/8e55452ecd<?php
class a {
/** @var self::STATE_* */
public int $status = self::STATE_A;
public const STATE_A = 0;
public const STATE_B = 1;
public const STATE_C = 2;
}
$a = new a;
/** @var array<string> */
$arr = [];
$status = $a->status;
if (array_key_exists($status, $arr)) {
echo $arr[$status];
}
|
It doesn't seem related to purity. I think it might be related with this line:
I'm not sure why but ClassConst seem to be excluded from array_key_exists assertions |
@orklah
As the result, the issue is solved. I guess
If you are alright I'll create a PR. |
I found these snippets: https://psalm.dev/r/ceab5bdfcd<?php
class a {
/** @var self::STATE_* */
public int $status = self::STATE_A;
public const STATE_A = 0;
public const STATE_B = 1;
public const STATE_C = 2;
}
$a = new a;
/** @var array<string> */
$arr = [];
if (array_key_exists($a->status, $arr)) {
echo $arr[$a->status];
}
|
Hey @hirokinoue ! Sorry for the delay of my reply. You're of course welcome to propose a PR, there's a good chance that the test suite will fail at some point if any side effect were to appear so go ahead! |
When using a property that is a union,
array_key_exists
assertions aren't parsed: https://psalm.dev/r/ceab5bdfcdHowever, if that same property is first copied into a variable, the assertions are parsed correctly: https://psalm.dev/r/8e55452ecd
This somewhat reminds me of a purity issue, but all non-magic properties should be pure by default.
The text was updated successfully, but these errors were encountered: