mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Detect bugs similar to that which caused #2832
This commit is contained in:
parent
9230b425e7
commit
0e23fab5d2
@ -170,7 +170,10 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
|
||||
if ($codebase->methods->methodExists(
|
||||
$method_id,
|
||||
$calling_function_id,
|
||||
$calling_function_id !== $method_id ? $code_location : null,
|
||||
!$calling_function_id
|
||||
|| strtolower($calling_function_id) !== strtolower((string) $method_id)
|
||||
? $code_location
|
||||
: null,
|
||||
null,
|
||||
$code_location->file_path
|
||||
)) {
|
||||
@ -319,8 +322,9 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
|
||||
|
||||
if (!$declaring_method_id) {
|
||||
if ($method_name === '__construct'
|
||||
|| $method_id === 'Closure::__invoke'
|
||||
|| $method_id === 'Closure::fromcallable'
|
||||
|| ($method_id->fq_class_name === 'Closure'
|
||||
&& ($method_id->method_name === 'fromcallable'
|
||||
|| $method_id->method_name === '__invoke'))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ class CallAnalyzer
|
||||
|
||||
if ((string) $method_id !== $source->getId()) {
|
||||
if ($context->collect_initializations) {
|
||||
if (isset($context->initialized_methods[$method_id])) {
|
||||
if (isset($context->initialized_methods[(string) $method_id])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ class CallAnalyzer
|
||||
$context->initialized_methods = [];
|
||||
}
|
||||
|
||||
$context->initialized_methods[$method_id] = true;
|
||||
$context->initialized_methods[(string) $method_id] = true;
|
||||
}
|
||||
|
||||
$project_analyzer->getMethodMutations(
|
||||
|
@ -454,21 +454,27 @@ class TypeAnalyzer
|
||||
$first_comparison_result = new TypeComparisonResult();
|
||||
$second_comparison_result = new TypeComparisonResult();
|
||||
|
||||
$either_contains = self::isAtomicContainedBy(
|
||||
$either_contains = (self::isAtomicContainedBy(
|
||||
$codebase,
|
||||
$type1_part,
|
||||
$type2_part,
|
||||
true,
|
||||
false,
|
||||
$first_comparison_result
|
||||
) || self::isAtomicContainedBy(
|
||||
)
|
||||
&& !$first_comparison_result->to_string_cast
|
||||
) || (self::isAtomicContainedBy(
|
||||
$codebase,
|
||||
$type2_part,
|
||||
$type1_part,
|
||||
true,
|
||||
false,
|
||||
$second_comparison_result
|
||||
) || ($first_comparison_result->type_coerced && $second_comparison_result->type_coerced);
|
||||
)
|
||||
&& !$second_comparison_result->to_string_cast
|
||||
) || ($first_comparison_result->type_coerced
|
||||
&& $second_comparison_result->type_coerced
|
||||
);
|
||||
|
||||
if ($either_contains) {
|
||||
return true;
|
||||
|
@ -2594,7 +2594,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $suppressed_issues
|
||||
* @param string[] $suppressed_issues
|
||||
*/
|
||||
private static function handleLiteralEquality(
|
||||
string $assertion,
|
||||
|
@ -3273,8 +3273,6 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
|
||||
if ($property_storage->type
|
||||
&& $property_storage->type !== $property_storage->signature_type
|
||||
&& (!$property_storage->signature_type
|
||||
|| $doc_var_group_type !== $property_storage->signature_type->getId())
|
||||
) {
|
||||
if (!$property_storage->signature_type) {
|
||||
$property_storage->type_location = $doc_var_location;
|
||||
|
@ -1135,6 +1135,15 @@ class ArrayAccessTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'LessSpecificReturnStatement',
|
||||
],
|
||||
'simpleXmlArrayFetchResultCannotEqualString' => [
|
||||
'<?php
|
||||
function foo(SimpleXMLElement $s) : void {
|
||||
$b = $s["a"];
|
||||
|
||||
if ($b === "hello" || $b === "1") {}
|
||||
}',
|
||||
'error_message' => 'TypeDoesNotContainType',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user