Skip to content

Commit 550cb27

Browse files
phpstan-botclaude
andcommitted
Add non-regression test for processBooleanNotSureConditionalTypes trivially-true skip
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 72f2b6e commit 550cb27

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,30 @@ function testTriviallyTrueConditionSkipped(array $aggregation, string $type): vo
5555

5656
assertType('non-falsy-string', $type);
5757
}
58+
59+
/**
60+
* Non-regression test for TypeSpecifier::processBooleanNotSureConditionalTypes
61+
* skipping trivially-always-true conditions.
62+
*
63+
* Without the fix, the BooleanAnd handler creates spurious conditional
64+
* expressions like "$type=non-falsy-string => $value=string" because
65+
* TypeCombinator::intersect(non-falsy-string, string) returns
66+
* non-falsy-string unchanged (is_string() on a non-falsy-string is
67+
* trivially always true). The spurious holder then fires inside
68+
* if ($type !== 'filter') and incorrectly narrows $value to string.
69+
*
70+
* @param non-falsy-string $type
71+
* @param int|string $value
72+
*/
73+
function testNotSureTriviallyTrueConditionSkipped(string $type, int|string $value): void
74+
{
75+
if (is_string($type) && is_int($value)) {
76+
return;
77+
}
78+
79+
if ($type !== 'filter') {
80+
assertType('int|string', $value);
81+
}
82+
83+
assertType('non-falsy-string', $type);
84+
}

0 commit comments

Comments
 (0)