1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix closure naming convention so it doesn’t confuse method id checks

This commit is contained in:
Matthew Brown 2017-12-05 01:47:49 -05:00
parent 83c65d4b2d
commit a8a1489a8f
4 changed files with 20 additions and 11 deletions

View File

@ -821,7 +821,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
return ($namespace ? strtolower($namespace) . '\\' : '') . strtolower($this->function->name);
}
return $this->getFilePath() . ':' . $this->function->getLine() . '::-closure';
return $this->getFilePath() . ':' . $this->function->getLine() . ':-:closure';
}
/**

View File

@ -1820,19 +1820,17 @@ class ExpressionChecker
if (strtolower($return_type->value) === 'static' || !$method_id) {
$return_type->value = $calling_class;
} elseif (strpos($method_id, ':-:closure') !== false) {
$return_type->value = $calling_class;
} else {
list(, $method_name) = explode('::', $method_id);
if ($method_name === '-closure') {
$return_type->value = $calling_class;
} else {
$appearing_method_id = MethodChecker::getAppearingMethodId(
$project_checker,
$calling_class . '::' . $method_name
);
$appearing_method_id = MethodChecker::getAppearingMethodId(
$project_checker,
$calling_class . '::' . $method_name
);
$return_type->value = explode('::', (string)$appearing_method_id)[0];
}
$return_type->value = explode('::', (string)$appearing_method_id)[0];
}
}
}

View File

@ -599,7 +599,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
$storage->visibility = ClassLikeChecker::VISIBILITY_PUBLIC;
}
} else {
$function_id = $cased_function_id = $this->file_path . ':' . $stmt->getLine() . '::-closure';
$function_id = $cased_function_id = $this->file_path . ':' . $stmt->getLine() . ':-:closure';
$storage = $this->file_storage->functions[$function_id] = new FunctionLikeStorage();
}

View File

@ -229,6 +229,17 @@ class FunctionCallTest extends TestCase
],
'error_levels' => ['MixedAssignment', 'MixedArgument'],
],
'uasort' => [
'<?php
uasort(
$manifest,
function ($a, $b) {
return strcmp($a["parent"],$b["parent"]);
}
);',
'assertions' => [],
'error_levels' => ['MixedArrayAccess', 'MixedArgument', 'UntypedParam', 'MissingClosureReturnType'],
],
'byRefAfterCallable' => [
'<?php
/**