mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Allow phantom classes in instanceof expression (#5498)
Fixes vimeo/psalm#5481
This commit is contained in:
parent
d4377c0baf
commit
d57dde0d15
@ -142,7 +142,7 @@ class Context
|
||||
/**
|
||||
* A list of classes checked with class_exists
|
||||
*
|
||||
* @var array<lowercase-string,bool>
|
||||
* @var array<lowercase-string,true>
|
||||
*/
|
||||
public $phantom_classes = [];
|
||||
|
||||
|
@ -59,16 +59,18 @@ class InstanceofAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
|
||||
$statements_analyzer,
|
||||
$fq_class_name,
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt->class),
|
||||
$context->self,
|
||||
$context->calling_method_id,
|
||||
$statements_analyzer->getSuppressedIssues(),
|
||||
false
|
||||
) === false) {
|
||||
return false;
|
||||
if (!isset($context->phantom_classes[strtolower($fq_class_name)])) {
|
||||
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
|
||||
$statements_analyzer,
|
||||
$fq_class_name,
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt->class),
|
||||
$context->self,
|
||||
$context->calling_method_id,
|
||||
$statements_analyzer->getSuppressedIssues(),
|
||||
false
|
||||
) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($codebase->alter_code) {
|
||||
|
@ -567,6 +567,13 @@ class ClassTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'instanceofWithPhantomClass' => [
|
||||
'<?php
|
||||
if (class_exists(NS\UnknonwClass::class)) {
|
||||
null instanceof NS\UnknonwClass;
|
||||
}
|
||||
',
|
||||
],
|
||||
'extendException' => [
|
||||
'<?php
|
||||
class ME extends Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user