Skip to content

Commit 0ea862f

Browse files
committed
Regression tests
Closes phpstan/phpstan#7880
1 parent 375e9f8 commit 0ea862f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

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

885+
public function testBug7880(): void
886+
{
887+
$this->checkExplicitMixed = true;
888+
$this->analyse([__DIR__ . '/data/bug-7880.php'], []);
889+
}
890+
891+
#[RequiresPhp('>= 8.1')]
892+
public function testBug7880b(): void
893+
{
894+
$this->checkExplicitMixed = true;
895+
$this->checkImplicitMixed = true;
896+
$this->analyse([__DIR__ . '/data/bug-7880b.php'], []);
897+
}
898+
885899
public function testBug13438f(): void
886900
{
887901
$this->checkExplicitMixed = true;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bug7880;
4+
5+
class C {
6+
/** @var array{a: string, b: string}|null */
7+
private $a = null;
8+
9+
public function foo(): void {
10+
if ($this->a !== null) {
11+
$this->a['b'] = "baz";
12+
}
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug7880b;
4+
5+
enum Undefined: string
6+
{
7+
case VALUE = '!@#$~~UNDEFINED~~$#@!';
8+
}
9+
10+
class Test1 {}
11+
12+
class Test {
13+
/**
14+
* @var Undefined|array<Test1>
15+
*/
16+
public array|Undefined $property = Undefined::VALUE;
17+
}
18+
19+
function (): void {
20+
$a = new Test();
21+
$a->property = [];
22+
$a->property[] = new Test1();
23+
};

0 commit comments

Comments
 (0)