mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix potential crash when calling magic setter
This commit is contained in:
parent
de5a031088
commit
bf578d1024
@ -423,7 +423,7 @@ class ExistingAtomicMethodCallAnalyzer extends CallAnalyzer
|
||||
|
||||
$codebase = $statements_analyzer->getCodebase();
|
||||
|
||||
$first_arg_value = $stmt->args[0]->value;
|
||||
$first_arg_value = $stmt->args[0]->value ?? null;
|
||||
if (!$first_arg_value instanceof PhpParser\Node\Scalar\String_) {
|
||||
return null;
|
||||
}
|
||||
@ -461,7 +461,9 @@ class ExistingAtomicMethodCallAnalyzer extends CallAnalyzer
|
||||
|
||||
// If a `@property` annotation is set, the type of the value passed to the
|
||||
// magic setter must match the annotation.
|
||||
$second_arg_type = $statements_analyzer->node_data->getType($stmt->args[1]->value);
|
||||
$second_arg_type = isset($stmt->args[1])
|
||||
? $statements_analyzer->node_data->getType($stmt->args[1]->value)
|
||||
: null;
|
||||
|
||||
if (isset($class_storage->pseudo_property_set_types['$' . $prop_name]) && $second_arg_type) {
|
||||
$pseudo_set_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
|
||||
|
@ -3646,6 +3646,24 @@ class PropertyTypeTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'PossiblyNullPropertyFetch',
|
||||
],
|
||||
'noCrashWhenCallingMagicSet' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function __set(string $s, mixed $value) : void {}
|
||||
}
|
||||
|
||||
(new A)->__set("foo");',
|
||||
'error_message' => 'TooFewArguments',
|
||||
],
|
||||
'noCrashWhenCallingMagicGet' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function __get(string $s) : mixed {}
|
||||
}
|
||||
|
||||
(new A)->__get();',
|
||||
'error_message' => 'TooFewArguments',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user