1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00

Fix #4167 - allow many issues for the same position

This commit is contained in:
Brown 2020-09-10 17:41:45 -04:00 committed by Daniil Gentili
parent 0e22f733b5
commit c291b93bbe
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 75 additions and 14 deletions

View File

@ -1457,18 +1457,18 @@ class ClassAnalyzer extends ClassLikeAnalyzer
}
if (!$storage->abstract && $uninitialized_typed_properties) {
$first_uninitialized_property = array_shift($uninitialized_typed_properties);
if ($first_uninitialized_property->location) {
if (IssueBuffer::accepts(
new MissingConstructor(
$class_storage->name . ' has an uninitialized variable ' . $uninitialized_variables[0] .
', but no constructor',
$first_uninitialized_property->location
),
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
foreach ($uninitialized_typed_properties as $uninitialized_property) {
if ($uninitialized_property->location) {
if (IssueBuffer::accepts(
new MissingConstructor(
$class_storage->name . ' has an uninitialized variable ' . $uninitialized_variables[0] .
', but no constructor',
$uninitialized_property->location
),
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
}
}
}

View File

@ -219,7 +219,10 @@ class IssueBuffer
fwrite(STDERR, "\nEmitting {$e->getShortLocation()} $issue_type {$e->getMessage()}\n$trace\n");
}
$emitted_key = $issue_type . '-' . $e->getShortLocation() . ':' . $e->getLocation()->getColumn();
$emitted_key = $issue_type
. '-' . $e->getShortLocation()
. ':' . $e->getLocation()->getColumn()
. ' ' . $e->getMessage();
if ($reporting_level === Config::REPORT_INFO) {
if ($issue_type === 'TaintedInput' || !self::alreadyEmitted($emitted_key)) {
@ -411,7 +414,8 @@ class IssueBuffer
$emitted_key = $issue->type
. '-' . $issue->file_name
. ':' . $issue->line_from
. ':' . $issue->column_from;
. ':' . $issue->column_from
. ' ' . $issue->message;
if (!self::alreadyEmitted($emitted_key)) {
self::$issues_data[$file_path][] = $issue;

View File

@ -408,6 +408,63 @@ class ErrorFixTest extends \Psalm\Tests\TestCase
],
'error_counts' => [0, 0, 0, 0],
],
'missingConstructorForTwoVars' => [
'files' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
class A {
protected int $x;
protected int $y;
}'
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
class A {
protected int $x = 0;
protected int $y;
}'
],
],
'error_counts' => [2, 1],
],
'missingConstructorForInheritedProperties' => [
'files' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
abstract class A {
public int $x;
public int $y;
}
class B extends A {
public function __construct() {}
}'
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
abstract class A {
public int $x = 0;
public int $y;
}
class B extends A {
public function __construct() {}
}'
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
abstract class A {
public int $x = 0;
public int $y = 0;
}
class B extends A {
public function __construct() {}
}'
],
],
'error_counts' => [2, 1, 0],
],
];
}
}