Skip to content
Permalink
Browse files

Fix #2380 - prevent string docblock for callable param

  • Loading branch information
muglug committed Nov 27, 2019
1 parent 4334ddc commit a154191922d14dcdde8ef348520a88d735d82304
Showing with 20 additions and 1 deletion.
  1. +9 −0 src/Psalm/Config.php
  2. +1 −1 src/Psalm/Internal/Analyzer/TypeAnalyzer.php
  3. +10 −0 tests/CallableTest.php
@@ -1031,11 +1031,14 @@ public function initializePlugins(ProjectAnalyzer $project_analyzer)
{
$codebase = $project_analyzer->getCodebase();
$project_analyzer->progress->debug('Initializing plugins...' . PHP_EOL);
$socket = new PluginRegistrationSocket($this, $codebase);
// initialize plugin classes earlier to let them hook into subsequent load process
foreach ($this->plugin_classes as $plugin_class_entry) {
$plugin_class_name = $plugin_class_entry['class'];
$plugin_config = $plugin_class_entry['config'];
try {
// Below will attempt to load plugins from the project directory first.
// Failing that, it will use registered autoload chain, which will load
@@ -1045,6 +1048,10 @@ public function initializePlugins(ProjectAnalyzer $project_analyzer)
if ($this->composer_class_loader
&& ($plugin_class_path = $this->composer_class_loader->findFile($plugin_class_name))
) {
$project_analyzer->progress->debug(
'Loading plugin ' . $plugin_class_name . ' via require'. PHP_EOL
);
/** @psalm-suppress UnresolvableInclude */
require_once($plugin_class_path);
} else {
@@ -1063,6 +1070,8 @@ public function initializePlugins(ProjectAnalyzer $project_analyzer)
} catch (\Throwable $e) {
throw new ConfigException('Failed to load plugin ' . $plugin_class_name, 0, $e);
}
$project_analyzer->progress->debug('Loaded plugin ' . $plugin_class_name . ' successfully'. PHP_EOL);
}
foreach ($this->filetype_scanner_paths as $extension => $path) {
@@ -1374,7 +1374,7 @@ public static function isAtomicContainedBy(
if ($container_type_part instanceof TCallable &&
(
$input_type_part instanceof TString
$input_type_part instanceof TLiteralString
|| $input_type_part instanceof TArray
|| $input_type_part instanceof ObjectLike
|| $input_type_part instanceof TList
@@ -1574,6 +1574,16 @@ public function __construct(string $name, callable $callable) {}
new Func("f", ["Foo", "bar"]);',
'error_message' => 'InvalidArgument'
],
'preventStringDocblockType' => [
'<?php
/**
* @param string $mapper
*/
function map2(callable $mapper): void {}
map2("foo");',
'error_message' => 'MismatchingDocblockParamType',
],
];
}
}

0 comments on commit a154191

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