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:
parent
d416e73e8b
commit
2846e549dd
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user