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

Fix #2594 - forbid isset check on null

This commit is contained in:
Matthew Brown 2020-01-11 15:58:40 -05:00
parent 7b887efc2c
commit 131fb97663
2 changed files with 20 additions and 3 deletions

View File

@ -173,9 +173,17 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
if (empty($existing_var_type->getAtomicTypes())) {
$failed_reconciliation = 2;
// @todo - I think there's a better way to handle this, but for the moment
// mixed will have to do.
return Type::getMixed();
if (IssueBuffer::accepts(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' on null var',
$code_location
),
$suppressed_issues
)) {
// fall through
}
return Type::getEmpty();
}
if ($existing_var_type->hasType('empty')) {

View File

@ -778,6 +778,15 @@ class IssetTest extends \Psalm\Tests\TestCase
}',
'error_message' => 'UndefinedVariable'
],
'issetNullVar' => [
'<?php
function four(?string $s) : void {
if ($s === null) {
if (isset($s)) {}
}
}',
'error_message' => 'TypeDoesNotContainType',
],
];
}
}