Open gready-hub opened 9 months ago
I found these snippets:
I guess the problem here is that referencing it in the try
sets possibly_undefined
or possibly_undefined_from_try
to true
which then spills over to the array assignment after it.
I suggest you start looking at TryAnalyzer
where setPossiblyUndefined
is called or set to true, shouldn't be too hard.
@kkmuffme , I found similar issue: https://psalm.dev/r/88913cdfa4 Should I file as a new ticket or it's exactly the same function used/buggy?
I found these snippets:
In my case it's important that array index is passed as a variable. If I would state b
then it become working as expected
I think there might be (at least) two issues here:
try
to be potentially undefinedI did some digging and did manage to resolve one of the bugs when using classes annotated with @psalm-immutable
and with properties using @psalm-readonly
. I did this by checking the ::has_mutations
property in the TryCatchAnalyzer
, however the has_mutations
trick doesn't work when we're not using those annotations.
Hello Devs.
Anytime we reference a source object-property through a try-catch Psalm makes the conclusion that the resulting array-key is possibly unset, even though the object property has no bearing on the array-key's existence.
Could possibly assist with a PR once this has behaviour has been verified to be invalid, and perhaps I could get a point in the right direction as well.
https://psalm.dev/r/a915915af4
Thanks!