mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #1339 - no crash when using self/static/parent in closure
This commit is contained in:
parent
8edb117451
commit
40a91eab6e
@ -1386,8 +1386,8 @@ class CallAnalyzer
|
||||
$fleshed_out_type = ExpressionAnalyzer::fleshOutType(
|
||||
$codebase,
|
||||
$param_type,
|
||||
$fq_class_name,
|
||||
$fq_class_name
|
||||
$fq_class_name ?: $context->self,
|
||||
$fq_class_name ?: $context->self
|
||||
);
|
||||
|
||||
if ($arg->unpack) {
|
||||
|
@ -976,6 +976,15 @@ class ExpressionAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
$return_type->value = $self_class;
|
||||
} elseif ($return_type_lc === 'parent') {
|
||||
if (!$self_class) {
|
||||
throw new \UnexpectedValueException(
|
||||
'Cannot handle ' . $return_type->value . ' when $self_class is empty'
|
||||
);
|
||||
}
|
||||
var_dump('here');
|
||||
|
||||
$return_type->value = $self_class;
|
||||
} else {
|
||||
$return_type->value = $codebase->classlikes->getUnAliasedName($return_type->value);
|
||||
|
@ -677,6 +677,31 @@ class CallableTest extends TestCase
|
||||
/** @psalm-suppress UndefinedClass */
|
||||
array_map(["two", "three"], ["one", "two"]);',
|
||||
],
|
||||
'callableSelfArg' => [
|
||||
'<?php
|
||||
class Clazz {
|
||||
/**
|
||||
* @param callable(static) $f
|
||||
*/
|
||||
function func1(callable $f): void {
|
||||
$f($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(self) $f
|
||||
*/
|
||||
function func2(callable $f): void {
|
||||
$f($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(parent) $f
|
||||
*/
|
||||
function func3(callable $f): void {
|
||||
$f($this);
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user