diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index 36767d81f..fddbd55ca 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -242,15 +242,17 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc $interface_exists = $codebase->interfaceExists($fq_class_name); if (!$class_exists && !$interface_exists) { - if (IssueBuffer::accepts( - new UndefinedClass( - 'Class or interface ' . $fq_class_name . ' does not exist', - $code_location, - $fq_class_name - ), - $suppressed_issues - )) { - return false; + if (!$codebase->classlikes->traitExists($fq_class_name)) { + if (IssueBuffer::accepts( + new UndefinedClass( + 'Class or interface ' . $fq_class_name . ' does not exist', + $code_location, + $fq_class_name + ), + $suppressed_issues + )) { + return false; + } } return null; diff --git a/src/Psalm/Codebase/ClassLikes.php b/src/Psalm/Codebase/ClassLikes.php index 8847d1c4f..573530496 100644 --- a/src/Psalm/Codebase/ClassLikes.php +++ b/src/Psalm/Codebase/ClassLikes.php @@ -508,6 +508,16 @@ class ClassLikes return $storage->parent_interfaces; } + /** + * @param string $fq_trait_name + * + * @return bool + */ + public function traitExists($fq_trait_name) + { + return $this->hasFullyQualifiedTraitName($fq_trait_name); + } + /** * Determine whether or not a class has the correct casing * diff --git a/tests/TraitTest.php b/tests/TraitTest.php index 95fa7b594..23a43d7d1 100644 --- a/tests/TraitTest.php +++ b/tests/TraitTest.php @@ -522,6 +522,20 @@ class TraitTest extends TestCase } }', ], + 'traitClassConst' => [ + '