-
Notifications
You must be signed in to change notification settings - Fork 659
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
Strange behavior when assigning to list and class-string-map #9412
Comments
I found these snippets: https://psalm.dev/r/1abd6b7b03<?php
final class ListTest
{
/** @var list */
private array $list = [];
public function set1(int $i, mixed $v): void {
$this->list[$i] = $v; // OK, it's an error
}
public function set2(int $i, mixed $v): void {
if (isset($this->list[$i])){} // no-op
$this->list[$i] = $v; // WRONG, it should still be an error
}
}
final class ClassMapTest
{
/** @var class-string-map<T,T> */
private array $map = [];
/**
* @template U of object
* @param class-string<U> $k
* @param U $v
*/
public function set1(string $k, object $v): void {
$this->map[$k] = $v; // false positive
}
/**
* @template U of object
* @param class-string<U> $k
* @param U $v
*/
public function set2(string $k, object $v): void {
if (isset($this->map[$k])){} // no-op
$this->map[$k] = $v; // somehow the false positive is silenced
}
}
|
The false-positive |
Seems fixed :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
False negative for list and false positive for class-string-map. I think these two problems are related:
https://psalm.dev/r/1abd6b7b03
I guess, also #4460 is related.
The text was updated successfully, but these errors were encountered: