From fbaf6afb305235a0d08de8f38293023c7c824a1a Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 3 Nov 2022 18:11:01 +0100 Subject: [PATCH] Try --- .../TypeVisitor/CanContainObjectTypeVisitor.php | 10 ++++++++-- tests/UnusedCodeTest.php | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/TypeVisitor/CanContainObjectTypeVisitor.php b/src/Psalm/Internal/TypeVisitor/CanContainObjectTypeVisitor.php index 91feb240b..ba88c86fc 100644 --- a/src/Psalm/Internal/TypeVisitor/CanContainObjectTypeVisitor.php +++ b/src/Psalm/Internal/TypeVisitor/CanContainObjectTypeVisitor.php @@ -32,10 +32,16 @@ class CanContainObjectTypeVisitor extends NodeVisitor { if ( $type instanceof Union - && UnionTypeComparator::canBeContainedBy($this->codebase, $type, new Union([new TObject()])) + && ( + UnionTypeComparator::canBeContainedBy($this->codebase, new Union([new TObject()]), $type) + && UnionTypeComparator::canBeContainedBy($this->codebase, $type, new Union([new TObject()])) + ) || $type instanceof Atomic - && AtomicTypeComparator::isContainedBy($this->codebase, $type, new TObject()) + && ( + AtomicTypeComparator::isContainedBy($this->codebase, new TObject(), $type) + || AtomicTypeComparator::isContainedBy($this->codebase, $type, new TObject()) + ) ) { $this->contains_object_type = true; return NodeVisitor::STOP_TRAVERSAL; diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index e692b2c59..0c46ed635 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -751,12 +751,14 @@ class UnusedCodeTest extends TestCase } } - function test(Foo|int $foo): bool { + function test(Foo|int $foo, mixed $bar, iterable $baz): bool { try { serialize(new Foo()); serialize([new Foo()]); serialize([[new Foo()]]); serialize($foo); + serialize($bar); + serialize($baz); unserialize(""); } catch (\Throwable) { return false;