Skip to content

Commit c37fb1e

Browse files
committed
testBug7229 - reflect real state
1 parent 622a84b commit c37fb1e

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/Rules/Arrays/NonexistentOffsetInArrayDimFetchRule.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ public function processNode(Node $node, Scope $scope): array
5656

5757
$isOffsetAccessible = $isOffsetAccessibleType->isOffsetAccessible();
5858

59-
if (
60-
$scope->isInExpressionAssign($node) && $isOffsetAccessible->yes()
61-
|| ($scope->isUndefinedExpressionAllowed($node) || $scope->isSpecified($node)) && !$isOffsetAccessible->no()
62-
) {
59+
if (($scope->isInExpressionAssign($node) || $scope->isUndefinedExpressionAllowed($node)) && $isOffsetAccessible->yes()) {
6360
return [];
6461
}
6562

@@ -86,7 +83,7 @@ public function processNode(Node $node, Scope $scope): array
8683
return [];
8784
}
8885

89-
if ($dimType === null) {
86+
if ($dimType === null || $scope->isSpecified($node)) {
9087
return [];
9188
}
9289

tests/PHPStan/Levels/data/arrayDimFetches-7.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
"message": "Cannot access offset 'foo' on iterable<int|string, object>.",
2929
"line": 58,
3030
"ignorable": true
31+
},
32+
{
33+
"message": "Cannot access offset 'foo' on iterable<int|string, object>.",
34+
"line": 66,
35+
"ignorable": true
3136
}
3237
]

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public function testRule(): void
111111
'Cannot access offset \'a\' on Closure(): void.',
112112
253,
113113
],
114+
[
115+
'Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void).',
116+
258,
117+
],
114118
[
115119
'Offset string does not exist on array<int, string>.',
116120
308,
@@ -395,7 +399,21 @@ public function testBug6508(): void
395399

396400
public function testBug7229(): void
397401
{
398-
$this->analyse([__DIR__ . '/data/bug-7229.php'], []);
402+
$this->checkExplicitMixed = true;
403+
$this->analyse([__DIR__ . '/data/bug-7229.php'], [
404+
[
405+
'Cannot access offset string on mixed.',
406+
24,
407+
],
408+
[
409+
'Cannot access offset string on mixed.',
410+
29,
411+
],
412+
[
413+
'Cannot access offset string on mixed.',
414+
32,
415+
],
416+
]);
399417
}
400418

401419
}

0 commit comments

Comments
 (0)