1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #2784 - no crash when get_class arg is mixed

This commit is contained in:
Brown 2020-02-10 14:44:33 -05:00
parent 074780547d
commit 89a0b101e4
2 changed files with 21 additions and 1 deletions

View File

@ -728,7 +728,12 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
if (isset($context->vars_in_scope[$var_id])) {
$atomic_type = $stmt->name->parts === ['get_class']
? new Type\Atomic\GetClassT($var_id, $context->vars_in_scope[$var_id])
? new Type\Atomic\GetClassT(
$var_id,
$context->vars_in_scope[$var_id]->hasMixed()
? Type::getObject()
: $context->vars_in_scope[$var_id]
)
: new Type\Atomic\GetTypeT($var_id);
$statements_analyzer->node_data->setType($real_stmt, new Type\Union([$atomic_type]));

View File

@ -831,6 +831,21 @@ class MethodCallTest extends TestCase
$date = new DateTime(null);',
'error_message' => 'NullArgument'
],
'noCrashOnGetClassMethodCall' => [
'<?php
class User {
/**
* @psalm-suppress MixedArgument
*/
public function give(): void{
/** @var mixed */
$model = null;
$class = \get_class($model);
$class::foo();
}
}',
'error_message' => 'InvalidStringClass',
],
];
}
}