Skip to content
Closed
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: 7 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3580,6 +3580,13 @@
continue;
}

if (
array_key_exists($exprString, $theirExpressionTypes)
&& !$holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->no()

Check warning on line 3585 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( array_key_exists($exprString, $theirExpressionTypes) - && !$holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->no() + && $holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->yes() ) { continue; }

Check warning on line 3585 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ if ( array_key_exists($exprString, $theirExpressionTypes) - && !$holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->no() + && !$theirExpressionTypes[$exprString]->getType()->isSuperTypeOf($holder->getType())->no() ) { continue; }

Check warning on line 3585 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( array_key_exists($exprString, $theirExpressionTypes) - && !$holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->no() + && $holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->yes() ) { continue; }

Check warning on line 3585 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ if ( array_key_exists($exprString, $theirExpressionTypes) - && !$holder->getType()->isSuperTypeOf($theirExpressionTypes[$exprString]->getType())->no() + && !$theirExpressionTypes[$exprString]->getType()->isSuperTypeOf($holder->getType())->no() ) { continue; }
) {
continue;
}

$typeGuards[$exprString] = $holder;
}

Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14411.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14411;

use function PHPStan\Testing\assertType;

/** @phpstan-impure */
function get_mixed(): mixed {
return random_int(0, 1) ? 'foo' : null;
}

/** @phpstan-impure */
function get_optional_int(): ?int {
return random_int(0, 1) ? 42 : null;
}

function (): void {
$a = get_mixed();

if ($a !== null) {
$b = $a;
}
else {
$b = get_optional_int();
}
if ($b !== null) {
assertType('mixed', $a);
if ($a === null) {
echo 'this is absolutely possible';
}
}
};
Loading