Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1292,9 +1292,14 @@ private static function getInstanceOfAssertions(
),
);
} elseif ($atomic_type instanceof TClassString && $atomic_type->as !== 'object') {
$literal_class_strings[] = new IsType(
$atomic_type->as_type ?: new TNamedObject($atomic_type->as),
);
$as_type = $atomic_type->as_type ?: new TNamedObject($atomic_type->as);
// an interface class-string can hold any implementor, so this is is_a, not a
// fixed type, and must not read as redundant (#11076)
if ($source->getCodebase()->interfaceExists($atomic_type->as)) {
$literal_class_strings[] = new IsAClass($as_type, false);
} else {
$literal_class_strings[] = new IsType($as_type);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/TypeReconciliation/RedundantConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,18 @@ function f(array $p) : void {
assert(!!$p);
}',
],
'instanceofClassStringVarIsNotRedundant' => [
'code' => '<?php
/**
* @param class-string<Traversable> $class
*/
function test(Traversable $input, string $class): bool {
if ($input instanceof $class) {
return true;
}
return false;
}',
],
];
}

Expand Down
Loading