mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #1458 by making instanceof static same as === static
This commit is contained in:
parent
4823e35f8e
commit
d845cdf0c5
@ -63,6 +63,10 @@ class AssertionFinder
|
||||
$var_type = $conditional->expr->inferredType ?? null;
|
||||
|
||||
foreach ($instanceof_types as $instanceof_type) {
|
||||
if ($instanceof_type[0] === '=') {
|
||||
$instanceof_type = substr($instanceof_type, 1);
|
||||
}
|
||||
|
||||
if ($codebase
|
||||
&& $var_type
|
||||
&& $inside_negation
|
||||
@ -1873,6 +1877,10 @@ class AssertionFinder
|
||||
} elseif ($this_class_name
|
||||
&& (in_array(strtolower($stmt->class->parts[0]), ['self', 'static'], true))
|
||||
) {
|
||||
if ($stmt->class->parts[0] === 'static') {
|
||||
return ['=' . $this_class_name];
|
||||
}
|
||||
|
||||
return [$this_class_name];
|
||||
}
|
||||
} elseif (isset($stmt->class->inferredType)) {
|
||||
|
@ -1355,6 +1355,14 @@ class TypeReconciliationTest extends TestCase
|
||||
$a->foo();
|
||||
}',
|
||||
],
|
||||
'instanceofStatic' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function foo(self $value): void {
|
||||
if ($value instanceof static) {}
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user