psalm
psalm copied to clipboard
Class constants where value starts with an operand are not recognized
If the value for a class constant starts with an operand, like !
or ~
, Psalm doesn't register it, and throws an UndefinedConstant
error.
https://psalm.dev/r/b100090d84
I found these snippets:
https://psalm.dev/r/b100090d84
<?php
class test {
public const BITFLAG_ALL = ~0;
public const BOOL_TRUE = !false;
}
print_r(test::BITFLAG_ALL);
print_r(test::BOOL_TRUE ? 'true' : 'false');
Psalm output (using commit f6fb715):
ERROR: UndefinedConstant - 7:9 - Constant test::BITFLAG_ALL is not defined
ERROR: UndefinedConstant - 8:9 - Constant test::BOOL_TRUE is not defined
As an aside, I've had a quick look through the code to see if I could fix this, but I'm having a hard time figuring out what part of the code this is likely to be in. If someone could give a pointer where this is likely to originate, I'd be happy to give it another go.
My first guess would be it's a parsing issue in either ParseTreeCreator
or TypeParser
, but it's possible the issue is somewhere else as well (and the fact that there's no parse error makes me doubt that guess). Still, if you add a breakpoint to see when the type is parsed, maybe you can follow it through and see why it's not being set properly.
Second guess would be ClassLikeNodeScanner::visitClassConstDeclaration
, that's probably where I'd start. I bet SimpleTypeInferer::infer
needs to be improved to support more unary ops.
Fixed in #8360