1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix possible crash when class-string class doesn’t exist

This commit is contained in:
Matthew Brown 2019-01-28 01:12:41 -05:00
parent 09ee6e3d13
commit 45058ea494
3 changed files with 47 additions and 1 deletions

View File

@ -523,7 +523,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$fleshed_out_type->check(
$this,
$property_type_location,
$this->getSuppressedIssues(),
array_merge($this->getSuppressedIssues(), $storage->suppressed_issues),
[],
false
);

View File

@ -263,15 +263,45 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
if ($lhs_type_part instanceof TNamedObject) {
$fq_class_name = $lhs_type_part->value;
if (!ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,
$fq_class_name,
new CodeLocation($source, $stmt->class),
$statements_analyzer->getSuppressedIssues(),
false
)) {
return false;
}
$intersection_types = $lhs_type_part->extra_types;
} elseif ($lhs_type_part instanceof Type\Atomic\TClassString
&& $lhs_type_part->as_type
) {
$fq_class_name = $lhs_type_part->as_type->value;
if (!ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,
$fq_class_name,
new CodeLocation($source, $stmt->class),
$statements_analyzer->getSuppressedIssues(),
false
)) {
return false;
}
$intersection_types = $lhs_type_part->as_type->extra_types;
} elseif ($lhs_type_part instanceof Type\Atomic\TLiteralClassString) {
$fq_class_name = $lhs_type_part->value;
if (!ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,
$fq_class_name,
new CodeLocation($source, $stmt->class),
$statements_analyzer->getSuppressedIssues(),
false
)) {
return false;
}
} elseif ($lhs_type_part instanceof Type\Atomic\TGenericParam
&& !$lhs_type_part->as->isMixed()
&& !$lhs_type_part->as->hasObject()

View File

@ -504,6 +504,22 @@ class MethodCallTest extends TestCase
(new C)::foo();',
'error_message' => 'InvalidStaticInvocation',
],
'noExceptionOnMissingClass' => [
'<?php
/** @psalm-suppress UndefinedClass */
class A
{
/** @var class-string<Foo> */
protected $bar;
public function foo(string $s): void
{
$bar = $this->bar;
$bar::baz();
}
}',
'error_message' => 'UndefinedClass'
],
];
}
}