mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Only collapse Traversable|array when we’re super sure it’s safe
Fixes #1333
This commit is contained in:
parent
27c99aed2f
commit
0f45d14fea
@ -204,6 +204,11 @@ class TypeCombination
|
||||
if (isset($combination->type_params['array'])
|
||||
&& (isset($combination->named_object_types['Traversable'])
|
||||
|| isset($combination->type_params['Traversable']))
|
||||
&& (($codebase && !$codebase->config->allow_phpstorm_generics)
|
||||
|| isset($combination->type_params['Traversable'])
|
||||
|| (isset($combination->named_object_types['Traversable'])
|
||||
&& $combination->named_object_types['Traversable']->from_docblock)
|
||||
)
|
||||
) {
|
||||
$array_param_types = $combination->type_params['array'];
|
||||
$traversable_param_types = $combination->type_params['Traversable'] ?? [Type::getMixed(), Type::getMixed()];
|
||||
|
@ -12,7 +12,7 @@ class AnnotationTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPhpStormGenericsWithValidArgument()
|
||||
public function testPhpStormGenericsWithValidArrayIteratorArgument()
|
||||
{
|
||||
Config::getInstance()->allow_phpstorm_generics = true;
|
||||
|
||||
@ -35,6 +35,29 @@ class AnnotationTest extends TestCase
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPhpStormGenericsWithValidTraversableArgument()
|
||||
{
|
||||
Config::getInstance()->allow_phpstorm_generics = true;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
function takesString(string $s): void {}
|
||||
|
||||
/** @param Traversable|string[] $i */
|
||||
function takesTraversableOfString(Traversable $i): void {
|
||||
foreach ($i as $s2) {
|
||||
takesString($s2);
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
@ -20,6 +20,7 @@ class TypeCombinationTest extends TestCase
|
||||
{
|
||||
foreach ($types as $k => $type) {
|
||||
$types[$k] = self::getAtomic($type);
|
||||
$types[$k]->setFromDocblock();
|
||||
}
|
||||
|
||||
/** @psalm-suppress InvalidArgument */
|
||||
|
Loading…
Reference in New Issue
Block a user