mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #26 - Allow refinement via type intersection
Not just via explict subsets
This commit is contained in:
parent
dcec735d11
commit
16e89a8c1c
@ -1253,7 +1253,9 @@ class TypeChecker
|
||||
return $new_type;
|
||||
}
|
||||
|
||||
if (!TypeChecker::isContainedBy($new_type, $existing_var_type) && $code_location) {
|
||||
if (!TypeChecker::isContainedBy($new_type, $existing_var_type) &&
|
||||
!TypeChecker::isContainedBy($existing_var_type, $new_type) &&
|
||||
$code_location) {
|
||||
if (IssueBuffer::accepts(
|
||||
new TypeDoesNotContainType(
|
||||
'Cannot resolve types for ' . $key . ' - ' . $existing_var_type . ' does not contain ' . $new_type,
|
||||
|
@ -1660,4 +1660,19 @@ class TypeTest extends PHPUnit_Framework_TestCase
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->check();
|
||||
}
|
||||
|
||||
public function testTypeRefinementWithIsNumeric()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function foo(string $a) : void {
|
||||
if (is_numeric($a)) {
|
||||
|
||||
}
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->check();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user