1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +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, $fq_class_name,
CodeLocation $code_location, CodeLocation $code_location,
array $suppressed_issues, array $suppressed_issues,
$inferred = true $inferred = true,
bool $allow_trait = false
) { ) {
$codebase = $statements_source->getCodebase(); $codebase = $statements_source->getCodebase();
if (empty($fq_class_name)) { if (empty($fq_class_name)) {
@ -233,7 +234,7 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
$interface_exists = $codebase->interfaceExists($fq_class_name); $interface_exists = $codebase->interfaceExists($fq_class_name);
if (!$class_exists && !$interface_exists) { if (!$class_exists && !$interface_exists) {
if (!$codebase->classlikes->traitExists($fq_class_name)) { if (!$allow_trait || !$codebase->classlikes->traitExists($fq_class_name)) {
if (IssueBuffer::accepts( if (IssueBuffer::accepts(
new UndefinedClass( new UndefinedClass(
'Class or interface ' . $fq_class_name . ' does not exist', 'Class or interface ' . $fq_class_name . ' does not exist',

View File

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

View File

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