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
NonInvariantDocblockPropertyType false positive when child property uses psalm-type #8515
Labels
Comments
I found these snippets: https://psalm.dev/r/f3c5eed362<?php
abstract class Father {
/** @var array<string, string> */
public array $a = [];
}
class Child extends Father {
/** @var array<string, string> */
public array $a = [
'key' => 'value',
];
}
https://psalm.dev/r/d5ddb3e4fc<?php
/**
* @psalm-type FatherType = array<string, string>
*/
abstract class Father {
/** @var FatherType */
public array $a = [];
}
/**
* @psalm-import-type FatherType from Father
*/
class Child extends Father {
/** @var FatherType */
public array $a = [
'key' => 'value',
];
}
https://psalm.dev/r/6facf65dd6<?php
declare(strict_types=1);
namespace Common;
/**
* @psalm-type MessageTemplatesType = array<string, string>
*/
abstract class AbstractClass
{
/**
* @psalm-var MessageTemplatesType Validation error message templates to be used when validators detect
* errors that needs showing.
*/
protected array $messageTemplates = [];
}
namespace App;
use Common\AbstractClass;
/**
* @psalm-import-type MessageTemplatesType from AbstractClass
*/
class ConcreteClass extends AbstractClass
{
/** @psalm-var MessageTemplatesType */
protected array $messageTemplates = [
'not_same' => 'Security validation failed. Please try again.',
'not_found' => 'We could not find a Use a lasting power of attorney account ' .
'with that email address and password. Check your details and try again.',
];
}
|
Just came accross the same issue: https://psalm.dev/r/6e05abde32 |
I found these snippets: https://psalm.dev/r/6e05abde32<?php
/**
* @psalm-type dataType = array<array-key, mixed>
*/
abstract class A {
/** @psalm-var dataType */
protected array $data = [];
}
/**
* @psalm-import-type dataType from A
*/
class B extends A {
/** @psalm-var dataType */
protected array $data = [ 'test' ];
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works if I declare the same type for both properties:
https://psalm.dev/r/f3c5eed362
But it does not work when using
@psalm-type
:https://psalm.dev/r/d5ddb3e4fc
Also: https://psalm.dev/r/6facf65dd6
See #6575 (comment):
The text was updated successfully, but these errors were encountered: