From 2846e549dd27bfe2fdcd7543abcf2cf48791d2e0 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 1 Mar 2018 11:19:23 -0500 Subject: [PATCH] Fix #546 - allow iterable phpstorm generics --- src/Psalm/Codebase/ClassLikes.php | 4 ++++ tests/AnnotationTest.php | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Psalm/Codebase/ClassLikes.php b/src/Psalm/Codebase/ClassLikes.php index 7d0faa991..ead6f2570 100644 --- a/src/Psalm/Codebase/ClassLikes.php +++ b/src/Psalm/Codebase/ClassLikes.php @@ -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); } diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 9e547d545..aa5b1d0f0 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -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', + 'analyzeFile('somefile.php', new Context()); + } + /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage InvalidScalarArgument