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

Add the means to ignore PossiblyNull* errors from the type itself

This commit is contained in:
github@muglug.com 2017-05-09 16:38:58 -04:00
parent a4bdca55e9
commit 9ff8736e53
5 changed files with 17 additions and 6 deletions

View File

@ -511,7 +511,7 @@ class AssignmentChecker
return null;
}
if ($lhs_type->isNullable()) {
if ($lhs_type->isNullable() && !$lhs_type->ignore_nullable_issues) {
if (IssueBuffer::accepts(
new PossiblyNullPropertyAssignment(
$lhs_var_id . ' with possibly null type \'' . $lhs_type . '\' cannot be assigned to',

View File

@ -694,7 +694,11 @@ class CallChecker
return null;
}
if ($class_type && is_string($stmt->name) && $class_type->isNullable()) {
if ($class_type &&
is_string($stmt->name) &&
$class_type->isNullable() &&
!$class_type->ignore_nullable_issues
) {
if (IssueBuffer::accepts(
new PossiblyNullReference(
'Cannot call method ' . $stmt->name . ' on possibly null variable ' . $var_id,
@ -1942,7 +1946,7 @@ class CallChecker
return null;
}
if ($input_type->isNullable()) {
if ($input_type->isNullable() && !$input_type->ignore_nullable_issues) {
if (IssueBuffer::accepts(
new PossiblyNullArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, possibly ' .

View File

@ -153,7 +153,7 @@ class FetchChecker
return null;
}
if ($stmt_var_type->isNullable()) {
if ($stmt_var_type->isNullable() && !$stmt_var_type->ignore_nullable_issues) {
if (IssueBuffer::accepts(
new PossiblyNullPropertyFetch(
'Cannot get property on possibly null variable ' . $stmt_var_id . ' of type ' . $stmt_var_type,

View File

@ -1326,7 +1326,7 @@ class ExpressionChecker
return;
}
if ($left_type->isNullable()) {
if ($left_type->isNullable() && !$left_type->ignore_nullable_issues) {
if (IssueBuffer::accepts(
new PossiblyNullOperand(
'Cannot concatenate with a possibly null ' . $left_type,
@ -1338,7 +1338,7 @@ class ExpressionChecker
}
}
if ($right_type->isNullable()) {
if ($right_type->isNullable() && !$right_type->ignore_nullable_issues) {
if (IssueBuffer::accepts(
new PossiblyNullOperand(
'Cannot concatenate with a possibly null ' . $right_type,

View File

@ -38,6 +38,13 @@ class Union
*/
public $failed_reconciliation = false;
/**
* Whether or not to ignore issues with possibly-null values
*
* @var boolean
*/
public $ignore_nullable_issues = false;
/**
* Constructs an Union instance
* @param array<int, Atomic> $types