diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index 31121a7f6..b407c5aea 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -1067,11 +1067,13 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc * * @param string $fq_class_name * @param FileChecker $file_checker + * @param CodeLocation $code_location * @return bool */ public static function classOrInterfaceExists( $fq_class_name, - FileChecker $file_checker + FileChecker $file_checker, + CodeLocation $code_location = null ) { if (!ClassChecker::classExists($fq_class_name, $file_checker) && !InterfaceChecker::interfaceExists($fq_class_name, $file_checker) @@ -1079,7 +1081,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc return false; } - if ($file_checker->project_checker->collect_references) { + if ($file_checker->project_checker->collect_references && $code_location) { $class_storage = ClassLikeChecker::$storage[strtolower($fq_class_name)]; $class_storage->referencing_locations[] = $code_location; } diff --git a/src/Psalm/Checker/Statements/Expression/CallChecker.php b/src/Psalm/Checker/Statements/Expression/CallChecker.php index e91e84099..975c4d9cf 100644 --- a/src/Psalm/Checker/Statements/Expression/CallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/CallChecker.php @@ -1434,14 +1434,18 @@ class CallChecker $offset_value_type = Type::parseString($arg->value->value); } - // register class if the class exists - if ($offset_value_type instanceof TNamedObject) { - ClassLikeChecker::checkFullyQualifiedClassLikeName( - $offset_value_type->value, - $statements_checker->getFileChecker(), - new CodeLocation($statements_checker->getSource(), $arg->value), - $statements_checker->getSuppressedIssues() - ); + if ($offset_value_type) { + foreach ($offset_value_type->types as $offset_value_type_part) { + // register class if the class exists + if ($offset_value_type_part instanceof TNamedObject) { + ClassLikeChecker::checkFullyQualifiedClassLikeName( + $offset_value_type_part->value, + $statements_checker->getFileChecker(), + new CodeLocation($statements_checker->getSource(), $arg->value), + $statements_checker->getSuppressedIssues() + ); + } + } } if ($generic_params === null) {