Skip to content

Commit c27d948

Browse files
committed
added regression test
1 parent efb6d78 commit c27d948

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,7 @@ static function (): void {
26692669
$isArrayPop ? $arrayArgType->popArray() : $arrayArgType->shiftArray(),
26702670
$isArrayPop ? $arrayArgNativeType->popArray() : $arrayArgNativeType->shiftArray(),
26712671
);
2672+
26722673
if ($arrayArg instanceof PropertyFetch || $arrayArg instanceof StaticPropertyFetch) {
26732674
$nodeCallback(new PropertyAssignNode($arrayArg, new TypeExpr($scope->getType($arrayArg)), false), $scope);
26742675
}

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,23 @@ public function testBug13438e(): void
882882
]);
883883
}
884884

885+
public function testBug2888(): void
886+
{
887+
$this->checkExplicitMixed = true;
888+
$this->analyse([__DIR__ . '/data/bug-2888.php'], [
889+
[
890+
'Property Bug2888\MyClass::$prop (array<int>) does not accept array<int|string>.',
891+
17,
892+
],
893+
[
894+
'Property Bug2888\MyClass::$prop (array<int>) does not accept array<int|string>.',
895+
18,
896+
],
897+
[
898+
'Property Bug2888\MyClass::$prop (array<int>) does not accept array<int|string>.',
899+
26,
900+
],
901+
]);
902+
}
903+
885904
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Bug2888;
4+
5+
class MyClass
6+
{
7+
/**
8+
* @var int[]
9+
*/
10+
private $prop = [];
11+
12+
/**
13+
* @return void
14+
*/
15+
public function foo()
16+
{
17+
array_push($this->prop, 'string');
18+
array_unshift($this->prop, 'string');
19+
}
20+
21+
/**
22+
* @return void
23+
*/
24+
public function bar()
25+
{
26+
$this->prop[] = 'string';
27+
}
28+
}

0 commit comments

Comments
 (0)