Skip to content
Permalink
Browse files

Fix erroneous callable parsing

  • Loading branch information...
muglug committed Aug 12, 2019
1 parent 4046b44 commit 669b50e8b478944d2b98f2727f2069ca3c887b8c
Showing with 15 additions and 1 deletion.
  1. +7 −1 src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php
  2. +8 −0 tests/CallableTest.php
@@ -2998,7 +2998,13 @@ public static function getFunctionIdsFromCallableArg(
}
if ($callable_arg instanceof PhpParser\Node\Scalar\String_) {
return [preg_replace('/^\\\/', '', $callable_arg->value)];
$potential_id = preg_replace('/^\\\/', '', $callable_arg->value);
if (preg_match('/^[A-Za-z0-9_]+(\\\[A-Za-z0-9_]+)*(::[A-Za-z0-9_]+)?$/', $potential_id)) {
return [$potential_id];
}
return [];
}
if (count($callable_arg->items) !== 2) {
@@ -927,6 +927,14 @@ function (int $x = 5) : int {
}
);',
],
'dontInferMethodIdWhenFormatDoesntFit' => [
'<?php
/** @param string|callable $p */
function f($p): array {
return [];
}
f("#b::a");'
],
];
}

0 comments on commit 669b50e

Please sign in to comment.
You can’t perform that action at this time.