Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ private static function intersectWithSubtractedType(
Type $b,
): Type
{
if ($a->getSubtractedType() === null) {
if ($a->getSubtractedType() === null || $b instanceof NeverType) {
return $a;
}

Expand Down Expand Up @@ -621,7 +621,10 @@ private static function intersectWithSubtractedType(
} elseif ($isBAlreadySubtracted->yes()) {
$subtractedType = self::remove($a->getSubtractedType(), $b);

if ($subtractedType instanceof NeverType) {
if (
$subtractedType instanceof NeverType
|| !$subtractedType->isSuperTypeOf($b)->no()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case checks if we "didn't remove" enough

) {
$subtractedType = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,12 @@ public function testBug10394(): void
$this->analyse([__DIR__ . '/data/bug-10394.php'], []);
}

public function testBug13628(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-13628.php'], []);
}

public function testBug9666(): void
{
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-13628.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace Bug13628;

function test(mixed $param): string {

$a = is_array($param) ? array_filter($param) : $param;
if ($a && is_array($a)) {
return 'array';
}
else {
return 'not-array';
}

}
8 changes: 8 additions & 0 deletions tests/PHPStan/Type/TypeCombinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@
],
UnionType::class,
'array|(callable(): mixed)|(TCode of array<int, int>|int (class Foo, parameter))',
],

Check failure on line 2127 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2127 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2127 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2127 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.
[
[
new MixedType(),
Expand All @@ -2133,6 +2133,14 @@
MixedType::class,
'mixed=implicit',
],
[
[
new ArrayType(new MixedType(), new StringType()),
new MixedType(false, new ArrayType(new MixedType(), new MixedType())),

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / Generate PHP baseline

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.

Check failure on line 2139 in tests/PHPStan/Type/TypeCombinatorTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

You're passing a non-default value PHPStan\Type\ArrayType to parameter $subtractedType but previous argument is passing default value to its parameter ($isExplicitMixed). You can skip it and use named argument for $subtractedType instead.
],
MixedType::class,
'mixed=implicit',
],
];

if (PHP_VERSION_ID < 80100) {
Expand Down
Loading