1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #1453 - traits are not valid classes

This commit is contained in:
Matthew Brown 2019-03-15 22:12:35 -04:00
parent b82709897a
commit ab832207a4
3 changed files with 15 additions and 3 deletions

View File

@ -183,7 +183,8 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
$fq_class_name,
CodeLocation $code_location,
array $suppressed_issues,
$inferred = true
$inferred = true,
bool $allow_trait = false
) {
$codebase = $statements_source->getCodebase();
if (empty($fq_class_name)) {
@ -233,7 +234,7 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
$interface_exists = $codebase->interfaceExists($fq_class_name);
if (!$class_exists && !$interface_exists) {
if (!$codebase->classlikes->traitExists($fq_class_name)) {
if (!$allow_trait || !$codebase->classlikes->traitExists($fq_class_name)) {
if (IssueBuffer::accepts(
new UndefinedClass(
'Class or interface ' . $fq_class_name . ' does not exist',

View File

@ -131,7 +131,8 @@ class ConstFetchAnalyzer
$fq_class_name,
new CodeLocation($statements_analyzer->getSource(), $stmt->class),
$statements_analyzer->getSuppressedIssues(),
false
false,
true
) === false) {
return false;
}

View File

@ -1024,6 +1024,16 @@ class TraitTest extends TestCase
}',
'error_message' => 'InaccessibleMethod'
],
'preventTraitPropertyType' => [
'<?php
trait T {}
class X {
/** @var T|null */
public $hm;
}',
'error_message' => 'UndefinedClass'
],
];
}
}