Skip to content

Commit 1a312aa

Browse files
Add some comments
1 parent 47445ba commit 1a312aa

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function testByRefInArray(): void
5151
assertType('array{}', $a);
5252

5353
$b = [&$a];
54-
assertType('mixed', $a);
54+
assertType('mixed', $a); // Could stay array{}
5555

5656
foo($b);
5757
assertType('mixed', $a);
@@ -63,7 +63,10 @@ function testByRefInArrayWithKey(): void
6363
assertType("'hello'", $a);
6464

6565
$b = ['key' => &$a];
66-
assertType('mixed', $a);
66+
assertType('mixed', $a); // Could stay 'hello'
67+
68+
$b['key'] = 42;
69+
assertType('mixed', $a); // Could be 42
6770
}
6871

6972
function testMultipleByRefInArray(): void
@@ -72,6 +75,13 @@ function testMultipleByRefInArray(): void
7275
$c = 'test';
7376

7477
$b = [&$a, 'normal', &$c];
75-
assertType('mixed', $a);
76-
assertType('mixed', $c);
78+
assertType('mixed', $a); // Could stay 1
79+
assertType('mixed', $c); // Could stay 'test'
80+
81+
$b[0] = 2;
82+
$b[1] = 'foo';
83+
$b[2] = 'bar';
84+
85+
assertType('mixed', $a); // Could be 2
86+
assertType('mixed', $c); // Could be 'bar'
7787
}

tests/PHPStan/Analyser/nsrt/bug-6799c.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
// https://3v4l.org/g5UjS
88

9+
$x = null;
10+
assertType('null', $x);
911
$a = [&$x];
12+
assertType('mixed', $x); // Could stay null
13+
1014
function doFoo(array &$arr) {
1115
$arr[0] = 'string';
1216
}
1317

14-
var_dump($x);
15-
assertType('mixed', $x);
1618
doFoo($a);
17-
var_dump($x);
18-
assertType('mixed', $x); // could be string
19+
assertType('mixed', $x);

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,12 +1521,7 @@ public function testBug6799c(): void
15211521
$this->checkMaybeUndefinedVariables = true;
15221522
$this->polluteScopeWithAlwaysIterableForeach = true;
15231523

1524-
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-6799c.php'], [
1525-
[
1526-
'Variable $x might not be defined.',
1527-
9,
1528-
],
1529-
]);
1524+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-6799c.php'], []);
15301525
}
15311526

15321527
}

0 commit comments

Comments
 (0)