Skip to content

Commit

Permalink
Merge pull request #6503 from orklah/TClassString_inference
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Sep 17, 2021
2 parents e4c6f97 + e9f3d5b commit 37362b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,8 @@ protected static function getInstanceOfTypes(
$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;
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/ClassLikeStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ function f(Exception $e): ?InvalidArgumentException {
}
}',
],
'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
/**
Expand Down

0 comments on commit 37362b3

Please sign in to comment.