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:
parent
074780547d
commit
89a0b101e4
@ -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]));
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user