1
0
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:
Bruce Weirdan 2021-09-17 21:54:54 +03:00 committed by GitHub
commit 37362b333c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -1173,6 +1173,8 @@ class AssertionFinder
$literal_class_strings[] = $atomic_type->value;
} elseif ($atomic_type instanceof Type\Atomic\TTemplateParamClass) {
$literal_class_strings[] = $atomic_type->param_name;
} elseif ($atomic_type instanceof Type\Atomic\TClassString && $atomic_type->as !== 'object') {
$literal_class_strings[] = $atomic_type->as;
}
}

View File

@ -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' => [
'<?php
/**