1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #43 - do not emit issues when doing instanceof interface checks

This commit is contained in:
Matt Brown 2017-01-13 12:52:32 -05:00
parent dc585ff22a
commit 82af023d6f
2 changed files with 19 additions and 1 deletions

View File

@ -643,7 +643,8 @@ class TypeChecker
return $new_type;
}
if (!TypeChecker::isContainedBy($new_type, $existing_var_type, $file_checker) &&
if (!InterfaceChecker::interfaceExists($new_var_type, $file_checker) &&
!TypeChecker::isContainedBy($new_type, $existing_var_type, $file_checker) &&
!TypeChecker::isContainedBy($existing_var_type, $new_type, $file_checker) &&
$code_location) {
if (IssueBuffer::accepts(

View File

@ -382,4 +382,21 @@ class InterfaceTest extends PHPUnit_Framework_TestCase
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
public function testTypeDoesNotContainType()
{
$stmts = self::$parser->parse('<?php
interface A { }
interface B {
function foo();
}
function bar(A $a) : void {
if ($a instanceof B) {
$a->foo();
}
}');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
}