File tree 3 files changed +39
-0
lines changed
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 45
45
use PHPStan \Type \TypeUtils ;
46
46
use PHPStan \Type \TypeWithClassName ;
47
47
use PHPStan \Type \UnionType ;
48
+ use function array_reverse ;
48
49
49
50
class TypeSpecifier
50
51
{
@@ -572,8 +573,15 @@ public function specifyTypesInCondition(
572
573
throw new \PHPStan \ShouldNotHappenException ();
573
574
}
574
575
576
+ $ vars = array_reverse ($ vars );
577
+
575
578
$ types = null ;
576
579
foreach ($ vars as $ var ) {
580
+ if ($ var instanceof Expr \Variable && is_string ($ var ->name )) {
581
+ if ($ scope ->hasVariableType ($ var ->name )->no ()) {
582
+ return new SpecifiedTypes ([], []);
583
+ }
584
+ }
577
585
if ($ expr instanceof Expr \Isset_) {
578
586
if (
579
587
$ var instanceof ArrayDimFetch
Original file line number Diff line number Diff line change @@ -10209,6 +10209,11 @@ public function dataCount(): array
10209
10209
return $ this ->gatherAssertTypes (__DIR__ . '/data/count-type.php ' );
10210
10210
}
10211
10211
10212
+ public function dataBug3985 (): array
10213
+ {
10214
+ return $ this ->gatherAssertTypes (__DIR__ . '/data/bug-3985.php ' );
10215
+ }
10216
+
10212
10217
/**
10213
10218
* @dataProvider dataBug2574
10214
10219
* @dataProvider dataBug2577
@@ -10293,6 +10298,7 @@ public function dataCount(): array
10293
10298
* @dataProvider dataBug1924
10294
10299
* @dataProvider dataExtraIntTypes
10295
10300
* @dataProvider dataCount
10301
+ * @dataProvider dataBug3985
10296
10302
* @param string $assertType
10297
10303
* @param string $file
10298
10304
* @param mixed ...$args
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug3985 ;
4
+
5
+ use PHPStan \TrinaryLogic ;
6
+ use function PHPStan \Analyser \assertVariableCertainty ;
7
+
8
+ class Foo
9
+ {
10
+ public function doFoo (array $ array ): void
11
+ {
12
+ foreach ($ array as $ val ) {
13
+ if (isset ($ foo [1 ])) {
14
+ assertVariableCertainty (TrinaryLogic::createNo (), $ foo );
15
+ }
16
+ }
17
+ }
18
+
19
+ public function doBar (): void
20
+ {
21
+ if (isset ($ foo [1 ])) {
22
+ assertVariableCertainty (TrinaryLogic::createNo (), $ foo );
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments