1
0
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:
Bruce Weirdan 2021-03-29 07:11:45 +03:00 committed by GitHub
parent d4377c0baf
commit d57dde0d15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 11 deletions

View File

@ -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 = [];

View File

@ -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) {

View File

@ -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 {