Skip to content

Commit 5f1a4a5

Browse files
committed
Downgrade arrays less
1 parent 9c98bba commit 5f1a4a5

6 files changed

Lines changed: 2283 additions & 1 deletion

File tree

src/Type/TypeCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ private static function processArrayTypes(array $arrayTypes, array $accessoryTyp
594594
}
595595
if (count($arrayTypes) === 1) {
596596
return [
597-
self::intersect(...self::optimizeConstantArrays($arrayTypes), ...$accessoryTypes),
597+
self::intersect(...$arrayTypes, ...$accessoryTypes),
598598
];
599599
}
600600

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,18 @@ public function testArrayUnion(): void
958958
$this->assertNoErrors($errors);
959959
}
960960

961+
public function testBug7963(): void
962+
{
963+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-7963.php');
964+
$this->assertNoErrors($errors);
965+
}
966+
967+
public function testBug7963Two(): void
968+
{
969+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-7963-two.php');
970+
$this->assertNoErrors($errors);
971+
}
972+
961973
/**
962974
* @param string[]|null $allAnalysedFiles
963975
* @return Error[]

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ public function dataFileAsserts(): iterable
10391039
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8033.php');
10401040
yield from $this->gatherAssertTypes(__DIR__ . '/data/constant-array-union-unshift.php');
10411041
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7987.php');
1042+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7963-three.php');
10421043
}
10431044

10441045
/**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Bug7963Three;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function (): void {
8+
/**
9+
* @var array{
10+
* foo: string|null,
11+
* bar: string|null,
12+
* baz: string|null,
13+
* abc: string|null,
14+
* qwe: string|null,
15+
* xyz: string|null,
16+
* } $arr
17+
*/
18+
$arr = [];
19+
20+
$str = 'Info: ';
21+
$str .= $arr['foo'] !== null ? "[foo:$arr[foo]]" : '[no-foo]';
22+
$str .= $arr['bar'] !== null ? "[bar:$arr[bar]]" : '[no-bar]';
23+
$str .= $arr['baz'] !== null ? "[baz:$arr[baz]]" : '[no-baz]';
24+
assertType('array{foo: string|null, bar: string|null, baz: string|null, abc: string|null, qwe: string|null, xyz: string|null}', $arr);
25+
$str .= $arr['abc'] !== null ? "[abc:$arr[abc]]" : '[no-abc]';
26+
$str .= $arr['qwe'] !== null ? "[qwe:$arr[qwe]]" : '[no-qwe]';
27+
$str .= $arr['xyz'] !== null ? "[xyz:$arr[xyz]]" : '[no-xyz]';
28+
assertType('array{foo: string|null, bar: string|null, baz: string|null, abc: string|null, qwe: string|null, xyz: string|null}', $arr);
29+
};

0 commit comments

Comments
 (0)