-
Notifications
You must be signed in to change notification settings - Fork 672
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
Magic property is inferred as mixed after method call #8748
Labels
Comments
I found these snippets: https://psalm.dev/r/10eec1df24<?php
/**
* @property array<string, string> $errors
*
* @psalm-seal-properties
*/
final class OrganizationObject {
public function __get(string $key): mixed
{
return [];
}
public function __set(string $key, mixed $a): void
{
}
public function updateErrors(): void {
/** @var array<string, string> */
$errors = [];
$this->errors = $errors;
}
public function updateStatus(): void {
$errors = $this->errors;
/** @psalm-trace $errors */;
$this->updateErrors();
$errors = $this->errors;
/** @psalm-trace $errors */;
}
}
https://psalm.dev/r/4e00eed4c5<?php
/**
* @property array<string, string> $errors
*
* @psalm-seal-properties
*/
final class OrganizationObject {
public function __get(string $key): mixed
{
return [];
}
public function __set(string $key, mixed $a): void
{
}
public function updateErrors(): void {
/** @var array<string, string> */
$errors = [];
//$this->errors = $errors;
}
public function updateStatus(): void {
$errors = $this->errors;
/** @psalm-trace $errors */;
$this->updateErrors();
$errors = $this->errors;
/** @psalm-trace $errors */;
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://psalm.dev/r/10eec1df24
This really surprised me, because it looks like Psalm is automatically creating some mistaken assertion on the property assigned in the
updateErrors
method, because if the assignment is removed fromupdateErrors
the error is fixed: https://psalm.dev/r/4e00eed4c5The text was updated successfully, but these errors were encountered: