Skip to content
Permalink
Browse files

Add error when reconciling impossible types

  • Loading branch information...
muglug committed May 28, 2019
1 parent 2010309 commit c9cfa7f010dea8b04f6637be9589e9eeb506d7a2
Showing with 50 additions and 6 deletions.
  1. +33 −6 src/Psalm/Type/Reconciler.php
  2. +17 −0 tests/AssertTest.php
@@ -93,10 +93,10 @@ public static function reconcileKeyedTypes(
$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 @@ public static function reconcileKeyedTypes(
}
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 @@ private static function handleNegatedType(
}
}
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)
@@ -1170,6 +1170,23 @@ function assertEqual($expected, $actual) : void {}
assertEqual($c, $d);',
'error_message' => 'TypeDoesNotContainType',
],
'assertNotSameDifferentTypes' => [
'<?php
/**
* @template T
* @param T $expected
* @param mixed $actual
* @param string $message
* @psalm-assert !=T $actual
* @return void
*/
function assertNotSame($expected, $actual, $message = "") {}
function bar(string $i, array $j) : void {
assertNotSame($i, $j);
}',
'error_message' => 'RedundantCondition',
],
];
}
}

0 comments on commit c9cfa7f

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