Skip to content

Commit 909a316

Browse files
phpstan-botclaude
andcommitted
Add non-regression test for TypeSpecifier trivially-true condition skip
Tests that processBooleanSureConditionalTypes correctly skips conditions where TypeCombinator::remove() returns the same type as the input. Without the TypeSpecifier fix, BooleanAnd creates spurious conditional expressions (e.g. $type=non-falsy-string) because remove(non-falsy-string, 'filter') has no effect. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2d5f0f6 commit 909a316

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/PHPStan/Analyser/nsrt/bug-10055.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,28 @@ function testScopeMerging(mixed $foo): void
3030
assertType('1', $a);
3131
}
3232
}
33+
34+
/**
35+
* Non-regression test for TypeSpecifier::processBooleanSureConditionalTypes
36+
* skipping trivially-always-true conditions.
37+
*
38+
* Without the fix, the BooleanAnd handler creates spurious conditional
39+
* expressions like "$type=non-falsy-string => ..." because
40+
* TypeCombinator::remove(non-falsy-string, 'filter') returns
41+
* non-falsy-string unchanged.
42+
*
43+
* @param array<string, mixed> $aggregation
44+
* @param non-falsy-string $type
45+
*/
46+
function testTriviallyTrueConditionSkipped(array $aggregation, string $type): void
47+
{
48+
if (empty($aggregation['field']) && $type !== 'filter') {
49+
return;
50+
}
51+
52+
if ($type !== 'filter') {
53+
assertType("array<string, mixed>", $aggregation);
54+
}
55+
56+
assertType('non-falsy-string', $type);
57+
}

0 commit comments

Comments
 (0)