Skip to content

Commit

Permalink
Fix #2324 - avoid fatal error on self string in callable
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 11, 2019
1 parent fbd1cf0 commit 658f86c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Psalm/Internal/Analyzer/TypeAnalyzer.php
Expand Up @@ -1740,7 +1740,6 @@ public static function getCallableMethodIdFromObjectLike(
return null;
}

$lhs = $input_type_part->properties[0];
$method_name = $rhs->getSingleStringLiteral()->value;

$class_name = null;
Expand All @@ -1755,6 +1754,13 @@ public static function getCallableMethodIdFromObjectLike(
}
}

if ($class_name === 'self'
|| $class_name === 'static'
|| $class_name === 'parent'
) {
return null;
}

if (!$class_name) {
if ($codebase && ($calling_method_id || $file_name)) {
$codebase->analyzer->addMixedMemberName(
Expand Down
16 changes: 16 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -957,6 +957,22 @@ function($a) {
);
}'
],
'noExceptionOnSelfString' => [
'<?php
class Fish {
public static function example(array $vals): void {
usort($vals, ["self", "compare"]);
}
/**
* @param mixed $a
* @param mixed $b
*/
public static function compare($a, $b): int {
return -1;
}
}',
],
];
}

Expand Down

0 comments on commit 658f86c

Please sign in to comment.