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
8 changes: 7 additions & 1 deletion src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1939,9 +1939,15 @@ private function processBooleanSureConditionalTypes(Scope $scope, SpecifiedTypes
continue;
}

$scopeType = $scope->getType($expr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need a similar fix in processBooleanNotSureConditionalTypes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but I didn't yet succeed finding a non regression test for processBooleanNotSureConditionalTypes, so I thought about letting this to another PR.

processBooleanNotSureConditionalTypes use intersect rather than remove so it's kinda different.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do agree your example is a bug but the similar changes in processBooleanNotSureConditionalTypes

$scopeType = $scope->getType($expr);
			$conditionType = TypeCombinator::intersect($scopeType, $type);
			if ($scopeType->equals($conditionType)) {
				continue;
			}

			$conditionExpressionTypes[$exprString] = ExpressionTypeHolder::createYes(
				$expr,
				$conditionType,
			);

Does not solve this issue.

I would prefer open an issue about it an run the bot to find a dedicated fix.

This Pr will unlock #5386 which closes ~7 issues

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok - opened a new bug phpstan/phpstan#14455

$conditionType = TypeCombinator::remove($scopeType, $type);
if ($scopeType->equals($conditionType)) {
continue;
}

$conditionExpressionTypes[$exprString] = ExpressionTypeHolder::createYes(
$expr,
TypeCombinator::remove($scope->getType($expr), $type),
$conditionType,
);
}

Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Analyser/nsrt/type-specifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace BugTypeSpecifier;

use function PHPStan\Testing\assertType;

/**
* @param array<string, mixed> $aggregation
* @param non-falsy-string $type
*/
function testTriviallyTrueConditionSkipped(array $aggregation, string $type): void
{
if (empty($aggregation['field']) && $type !== 'filter') {
return;
}

if ($type !== 'filter') {
assertType("array<string, mixed>", $aggregation);
}

assertType('non-falsy-string', $type);
}
Loading