Skip to content
Permalink
Browse files

Fix #2594 - forbid isset check on null

  • Loading branch information
muglug committed Jan 11, 2020
1 parent 7b887ef commit 131fb97663e6d651f417ff3ab90ee76458408b0b
Showing with 20 additions and 3 deletions.
  1. +11 −3 src/Psalm/Internal/Type/AssertionReconciler.php
  2. +9 −0 tests/TypeReconciliation/IssetTest.php
@@ -173,9 +173,17 @@ public static function reconcile(
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')) {
@@ -778,6 +778,15 @@ function bar(): void {
}',
'error_message' => 'UndefinedVariable'
],
'issetNullVar' => [
'<?php
function four(?string $s) : void {
if ($s === null) {
if (isset($s)) {}
}
}',
'error_message' => 'TypeDoesNotContainType',
],
];
}
}

0 comments on commit 131fb97

Please sign in to comment.
You can’t perform that action at this time.