diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index ea7969384..278763628 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -93,10 +93,10 @@ class Reconciler $base_key = array_shift($key_parts); if (!isset($new_types[$base_key])) { - $new_types[$base_key] = [['!=bool'], ['!=int'], ['=isset']]; + $new_types[$base_key] = [['!~bool'], ['!~int'], ['=isset']]; } else { - $new_types[$base_key][] = ['!=bool']; - $new_types[$base_key][] = ['!=int']; + $new_types[$base_key][] = ['!~bool']; + $new_types[$base_key][] = ['!~int']; $new_types[$base_key][] = ['=isset']; } @@ -129,10 +129,10 @@ class Reconciler } if (!isset($new_types[$base_key])) { - $new_types[$base_key] = [['!=bool'], ['!=int'], ['=isset']]; + $new_types[$base_key] = [['!~bool'], ['!~int'], ['=isset']]; } else { - $new_types[$base_key][] = ['!=bool']; - $new_types[$base_key][] = ['!=int']; + $new_types[$base_key][] = ['!~bool']; + $new_types[$base_key][] = ['!~int']; $new_types[$base_key][] = ['=isset']; } } @@ -1972,6 +1972,33 @@ class Reconciler } } + if ($is_strict_equality + && $new_var_type !== 'isset' + && ($key !== '$this' + || !($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer)) + ) { + $new_var_type = Type::parseString($new_var_type); + + if ($key + && $code_location + && !TypeAnalyzer::canExpressionTypesBeIdentical( + $statements_analyzer->getCodebase(), + $existing_var_type, + $new_var_type + ) + ) { + self::triggerIssueForImpossible( + $existing_var_type, + $old_var_type_string, + $key, + '!=' . $new_var_type, + true, + $code_location, + $suppressed_issues + ); + } + } + if (empty($existing_var_type->getTypes())) { if ($key !== '$this' || !($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer) diff --git a/tests/AssertTest.php b/tests/AssertTest.php index cf68c5f81..0f12e5516 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -1170,6 +1170,23 @@ class AssertTest extends TestCase assertEqual($c, $d);', 'error_message' => 'TypeDoesNotContainType', ], + 'assertNotSameDifferentTypes' => [ + ' 'RedundantCondition', + ], ]; } }