From a8851ff42539a8add8ae1bea426d48605a1a600c Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 13 Dec 2018 01:54:15 -0500 Subject: [PATCH] Improve handling of T::class when mixed is passed --- .../Statements/Expression/Fetch/ConstFetchAnalyzer.php | 3 ++- src/Psalm/Type/Union.php | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php index b0c71344f..6762113c6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -90,7 +90,8 @@ class ConstFetchAnalyzer ) { $codebase = $statements_analyzer->getCodebase(); - if ($context->check_consts + if (($context->check_consts + || ($stmt->name instanceof PhpParser\Node\Identifier && $stmt->name->name === 'class')) && $stmt->class instanceof PhpParser\Node\Name ) { $first_part_lc = strtolower($stmt->class->parts[0]); diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 77acbca51..87f1eabcb 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -778,6 +778,8 @@ class Union if ($valid_input_atomic_types) { $generic_params[$atomic_type->param_name] = new Union($valid_input_atomic_types); $generic_params[$atomic_type->param_name]->setFromDocblock(); + } else { + $generic_params[$atomic_type->param_name] = Type::getMixed(); } } } else { @@ -848,7 +850,9 @@ class Union $is_mixed = false; foreach ($this->types as $key => $atomic_type) { - if (isset($template_types[$key])) { + if ($atomic_type instanceof Type\Atomic\TGenericParam + && isset($template_types[$key]) + ) { $keys_to_unset[] = $key; $template_type = clone $template_types[$key];