Skip to content
Permalink
Browse files

#2579 TooManyArguments was triggered if the variadic function declare…

…d at the autoloader file. Fixed. (#2580)
  • Loading branch information
incrize authored and muglug committed Jan 12, 2020
1 parent cfbf0df commit 39a822759d0dc5b1a2600d1f9c27ef4f3077415d
@@ -1180,14 +1180,19 @@ protected static function checkFunctionLikeArgumentsMatch(
$codebase = $statements_analyzer->getCodebase();

if ($method_id) {
if ($in_call_map || !strpos($method_id, '::')) {
if (!$in_call_map && strpos($method_id, '::')) {
$fq_class_name = explode('::', $method_id)[0];
}

if ($function_storage) {
$is_variadic = $function_storage->variadic;
} elseif ($fq_class_name === null) {
$is_variadic = $codebase->functions->isVariadic(
$codebase,
strtolower($method_id),
$statements_analyzer->getRootFilePath()
);
} else {
$fq_class_name = explode('::', $method_id)[0];
$is_variadic = $codebase->methods->isVariadic($method_id);
}
}
@@ -2317,7 +2317,7 @@ public function getUncaughtThrows(Context $context)
$is_expected = false;

foreach ($ignored_exceptions_and_descendants as $expected_exception => $_) {
if ($expected_exception === $possibly_thrown_exception
if ($expected_exception === strtolower($possibly_thrown_exception)
|| $this->codebase->classExtends($possibly_thrown_exception, $expected_exception)
) {
$is_expected = true;
@@ -1,7 +1,11 @@
<?php
namespace Psalm\Tests;

use Psalm\Config;
use Psalm\Context;
use Psalm\Tests\Internal\Provider;
use function dirname;
use function getcwd;

class VariadicTest extends TestCase
{
@@ -29,6 +33,38 @@ function f(int ...$a_list) {
$this->analyzeFile('somefile.php', new Context());
}

/**
* @throws \Psalm\Exception\ConfigException
* @return void
*/
public function testVariadicFunctionFromAutoloadFile()
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
'<?xml version="1.0"?>
<psalm
autoloader="tests/fixtures/stubs/custom_functions.php"
>
<projectFiles>
<directory name="src" />
</projectFiles>
</psalm>'
)
);

$file_path = getcwd() . '/src/somefile.php';

$this->addFile(
$file_path,
'<?php
variadic2(16, 30);
'
);

$this->analyzeFile($file_path, new Context());
}

/**
* @return iterable<string,array{string,1?:array<string,string>,2?:string[]}>
*/
@@ -91,4 +127,25 @@ function g(string ...$a_list) {
],
];
}

/**
* @param Config $config
*
* @return \Psalm\Internal\Analyzer\ProjectAnalyzer
*/
private function getProjectAnalyzerWithConfig(Config $config)
{
$project_analyzer = new \Psalm\Internal\Analyzer\ProjectAnalyzer(
$config,
new \Psalm\Internal\Provider\Providers(
$this->file_provider,
new Provider\FakeParserCacheProvider()
)
);
$project_analyzer->setPhpVersion('7.3');

$config->visitComposerAutoloadFiles($project_analyzer, null);

return $project_analyzer;
}
}
@@ -10,3 +10,8 @@ function barBar(string $a) : string
function variadic()
{
}

function variadic2() : array
{
return func_get_args();
}

0 comments on commit 39a8227

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