File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -763,7 +763,7 @@ public function specifyTypesInCondition(
763763 );
764764 }
765765
766- if ((new ConstantBooleanType (false ))->isSuperTypeOf ($ scope ->getType ($ expr ->right ))->yes ()) {
766+ if ((new ConstantBooleanType (false ))->isSuperTypeOf ($ scope ->getType ($ expr ->right )-> toBoolean () )->yes ()) {
767767 return $ this ->create (
768768 $ expr ->left ,
769769 new NullType (),
Original file line number Diff line number Diff line change @@ -415,6 +415,7 @@ public function dataFileAsserts(): iterable
415415 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-987.php ' );
416416 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-3677.php ' );
417417 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-4215.php ' );
418+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-10224.php ' );
418419 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-4695.php ' );
419420 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-2977.php ' );
420421 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-3190.php ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug10224 ;
4+
5+ use PHPStan \TrinaryLogic ;
6+ use function PHPStan \Testing \assertType ;
7+ use function PHPStan \Testing \assertVariableCertainty ;
8+
9+ function foo (bool $ condition ): ?string
10+ {
11+ if ($ condition ) {
12+ $ foo = 'bar ' ;
13+ }
14+ if ($ foo ?? null ) {
15+ assertVariableCertainty (TrinaryLogic::createYes (), $ foo );
16+ return $ foo ;
17+ }
18+ return null ;
19+ }
20+
21+ function bar (bool $ condition , $ a ): ?string
22+ {
23+ if ($ condition ) {
24+ $ foo = $ a ;
25+ }
26+ if ($ foo ?? null ) {
27+ assertVariableCertainty (TrinaryLogic::createYes (), $ foo );
28+ assertType ("mixed~null " , $ foo );
29+ return $ foo ;
30+ }
31+ return null ;
32+ }
You can’t perform that action at this time.
0 commit comments