1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix incorrect issue type emitted for static properties

This commit is contained in:
Matthew Brown 2018-03-20 23:19:26 -04:00
parent 69479f9f6e
commit f47012823e
2 changed files with 30 additions and 14 deletions

View File

@ -721,18 +721,34 @@ class PropertyAssignmentChecker
$assignment_value_type,
$class_property_type
)) {
if (IssueBuffer::accepts(
new InvalidPropertyAssignment(
$var_id . ' with declared type \'' . $class_property_type . '\' cannot be assigned type \'' .
$assignment_value_type . '\'',
new CodeLocation(
$statements_checker->getSource(),
$assignment_value ?: $stmt
)
),
$statements_checker->getSuppressedIssues()
)) {
return false;
if (TypeChecker::canBeIdenticalTo($codebase, $assignment_value_type, $class_property_type)) {
if (IssueBuffer::accepts(
new PossiblyInvalidPropertyAssignmentValue(
$var_id . ' with declared type \'' . $class_property_type . '\' cannot be assigned type \'' .
$assignment_value_type . '\'',
new CodeLocation(
$statements_checker->getSource(),
$assignment_value ?: $stmt
)
),
$statements_checker->getSuppressedIssues()
)) {
return false;
}
} else {
if (IssueBuffer::accepts(
new InvalidPropertyAssignmentValue(
$var_id . ' with declared type \'' . $class_property_type . '\' cannot be assigned type \'' .
$assignment_value_type . '\'',
new CodeLocation(
$statements_checker->getSource(),
$assignment_value ?: $stmt
)
),
$statements_checker->getSuppressedIssues()
)) {
return false;
}
}
}

View File

@ -90,7 +90,7 @@ class FileReferenceProvider
/**
* @param array<string, array<string,bool>> $references
* @psalm-suppress InvalidPropertyAssignment
* @psalm-suppress PossiblyInvalidPropertyAssignmentValue
*
* @return void
*/
@ -200,7 +200,7 @@ class FileReferenceProvider
/**
* @return bool
* @psalm-suppress MixedAssignment
* @psalm-suppress InvalidPropertyAssignment
* @psalm-suppress PossiblyInvalidPropertyAssignmentValue
*/
public static function loadReferenceCache()
{