1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #546 - allow iterable phpstorm generics

This commit is contained in:
Matt Brown 2018-03-01 11:19:23 -05:00
parent d416e73e8b
commit 2846e549dd
2 changed files with 27 additions and 0 deletions

View File

@ -487,6 +487,10 @@ class ClassLikes
*/
public function interfaceExtends($interface_name, $possible_parent)
{
if (strtolower($interface_name) === 'iterable' && strtolower($possible_parent) === 'traversable') {
return true;
}
return in_array($possible_parent, $this->getParentInterfaces($interface_name), true);
}

View File

@ -35,6 +35,29 @@ class AnnotationTest extends TestCase
$this->analyzeFile('somefile.php', new Context());
}
/**
* @return void
*/
public function testPhpStormGenericsWithValidIterableArgument()
{
Config::getInstance()->allow_phpstorm_generics = true;
$this->addFile(
'somefile.php',
'<?php
function takesString(string $s): void {}
/** @param iterable|string[] $i */
function takesArrayIteratorOfString(iterable $i): void {
foreach ($i as $s2) {
takesString($s2);
}
}'
);
$this->analyzeFile('somefile.php', new Context());
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage InvalidScalarArgument