mirror of
https://github.com/danog/psalm.git
synced 2024-12-13 09:47:29 +01:00
Merge pull request #6503 from orklah/TClassString_inference
This commit is contained in:
commit
37362b333c
@ -1173,6 +1173,8 @@ class AssertionFinder
|
|||||||
$literal_class_strings[] = $atomic_type->value;
|
$literal_class_strings[] = $atomic_type->value;
|
||||||
} elseif ($atomic_type instanceof Type\Atomic\TTemplateParamClass) {
|
} elseif ($atomic_type instanceof Type\Atomic\TTemplateParamClass) {
|
||||||
$literal_class_strings[] = $atomic_type->param_name;
|
$literal_class_strings[] = $atomic_type->param_name;
|
||||||
|
} elseif ($atomic_type instanceof Type\Atomic\TClassString && $atomic_type->as !== 'object') {
|
||||||
|
$literal_class_strings[] = $atomic_type->as;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,6 +458,23 @@ class ClassLikeStringTest extends TestCase
|
|||||||
}
|
}
|
||||||
}',
|
}',
|
||||||
],
|
],
|
||||||
|
'instanceofClassStringNotLiteral' => [
|
||||||
|
'<?php
|
||||||
|
final class Z {
|
||||||
|
/**
|
||||||
|
* @psalm-var class-string<stdClass> $class
|
||||||
|
*/
|
||||||
|
private string $class = stdClass::class;
|
||||||
|
|
||||||
|
public function go(object $object): ?stdClass {
|
||||||
|
$a = $this->class;
|
||||||
|
if ($object instanceof $a) {
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
],
|
||||||
'returnTemplatedClassString' => [
|
'returnTemplatedClassString' => [
|
||||||
'<?php
|
'<?php
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user