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:
parent
5b7d190640
commit
b9f55b7b8b
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user