1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix instanceof static and isa (static::class) handling

This commit is contained in:
Brown 2020-03-24 18:58:15 -04:00
parent 94b246b987
commit 467da32f84
4 changed files with 29 additions and 18 deletions

View File

@ -276,7 +276,7 @@ class DocComment
$special_key,
[
'return', 'param', 'template', 'var', 'type',
'template-covariant', 'property', 'method',
'template-covariant', 'property', 'property-read', 'property-write', 'method',
'assert', 'assert-if-true', 'assert-if-false', 'suppress',
'ignore-nullable-return', 'override-property-visibility',
'override-method-visibility', 'seal-properties', 'seal-methods',

View File

@ -1708,7 +1708,11 @@ class AssertionFinder
) {
$class_node = $second_arg->class;
if ($class_node->parts === ['static'] || $class_node->parts === ['self']) {
if ($class_node->parts === ['static']) {
if ($this_class_name) {
$if_types[$first_var_name] = [[$prefix . $is_a_prefix . $this_class_name . '&static']];
}
} elseif ($class_node->parts === ['self']) {
if ($this_class_name) {
$if_types[$first_var_name] = [[$prefix . $is_a_prefix . $this_class_name]];
}
@ -2233,7 +2237,7 @@ class AssertionFinder
&& (in_array(strtolower($stmt->class->parts[0]), ['self', 'static'], true))
) {
if ($stmt->class->parts[0] === 'static') {
return ['=' . $this_class_name];
return ['=' . $this_class_name . '&static'];
}
return [$this_class_name];

View File

@ -530,7 +530,14 @@ abstract class Type
$first_type = array_shift($keyed_intersection_types);
$first_type->extra_types = $keyed_intersection_types;
if (count($keyed_intersection_types) === 1
&& isset($keyed_intersection_types['static'])
&& $first_type instanceof TNamedObject
) {
$first_type->was_static = true;
} else {
$first_type->extra_types = $keyed_intersection_types;
}
return $first_type;
}

View File

@ -422,31 +422,31 @@ class MethodSignatureTest extends TestCase
'selfReturnShouldBeParent' => [
'<?php
class A {
/** @return self */
public function foo() {
return new A();
}
/** @return self */
public function foo() {
return new A();
}
}
class B extends A {
public function foo() {
return new A();
}
public function foo() {
return new A();
}
}',
],
'staticReturnShouldBeStatic' => [
'<?php
class A {
/** @return static */
public static function foo() {
return new A();
}
/** @return static */
public static function foo() {
return new static();
}
}
class B extends A {
public static function foo() {
return new B();
}
public static function foo() {
return new static();
}
}
$b = B::foo();',