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

Fix #680 - add intersection to cloned type

This commit is contained in:
Matt Brown 2018-04-18 10:59:46 -04:00
parent 5b7d190640
commit b9f55b7b8b
2 changed files with 26 additions and 1 deletions

View File

@ -837,7 +837,7 @@ class Reconciler
$type_coerced_from_mixed,
$atomic_to_string_cast
)) {
$acceptable_atomic_types[] = $existing_var_type_part;
$acceptable_atomic_types[] = clone $existing_var_type_part;
continue;
}
@ -845,6 +845,7 @@ class Reconciler
&& ($codebase->classExists($existing_var_type_part->value)
|| $codebase->interfaceExists($existing_var_type_part->value))
) {
$existing_var_type_part = clone $existing_var_type_part;
$existing_var_type_part->addIntersectionType($new_type_part);
$acceptable_atomic_types[] = $existing_var_type_part;
}

View File

@ -397,6 +397,30 @@ class InterfaceTest extends TestCase
function takesIterable(iterable $i): void {}',
],
'interfaceInstanceofInterfaceOrClass' => [
'<?php
interface A {}
class B extends Exception {}
function foo(Throwable $e): void {
if ($e instanceof A || $e instanceof B) {
return;
}
return;
}
class C extends Exception {}
interface D {}
function bar(Throwable $e): void {
if ($e instanceof C || $e instanceof D) {
return;
}
return;
}',
],
];
}