mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add error when reconciling impossible types
This commit is contained in:
parent
201030928d
commit
c9cfa7f010
@ -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)
|
||||
|
@ -1170,6 +1170,23 @@ class AssertTest extends TestCase
|
||||
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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user