Skip to content

Commit 02b301b

Browse files
ondrejmirtesclaude
andcommitted
Add regression tests for evaluation-point array item types
Closes phpstan/phpstan#13944 Closes phpstan/phpstan#12207 Closes phpstan/phpstan#7155 Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 3b32ef5 commit 02b301b

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12207;
4+
5+
use Generator;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
11+
/**
12+
* @return Generator<string, array{0: string, 1: array<string, string>}>
13+
*/
14+
public function bar(): Generator
15+
{
16+
yield 'foo' => [
17+
$a = 'string',
18+
['string' => $a],
19+
];
20+
}
21+
22+
public function baz(): void
23+
{
24+
$value = [
25+
$a = 'string',
26+
['string' => $a],
27+
];
28+
assertType("array{'string', array{string: 'string'}}", $value);
29+
}
30+
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Bug13944;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array{
9+
* "when@dev"?: array<string, array{resource: string}>,
10+
* "when@stage"?: array<string, array{resource: string}>,
11+
* } $config
12+
*/
13+
function config(array $config): void
14+
{
15+
}
16+
17+
config([
18+
'when@dev' => $does_not_work = [
19+
'controllers' => [
20+
'resource' => 'routing.controllers',
21+
],
22+
],
23+
'when@stage' => $does_not_work,
24+
]);
25+
26+
assertType("array{'when@dev': array{controllers: array{resource: 'routing.controllers'}}, 'when@stage': array{controllers: array{resource: 'routing.controllers'}}}", [
27+
'when@dev' => $does_not_work,
28+
'when@stage' => $does_not_work,
29+
]);
30+
31+
assertType("array{'when@dev': array{controllers: array{resource: 'routing.controllers'}}, 'when@stage': array{controllers: array{resource: 'routing.controllers'}}}", [
32+
'when@dev' => $defined_inside = [
33+
'controllers' => [
34+
'resource' => 'routing.controllers',
35+
],
36+
],
37+
'when@stage' => $defined_inside,
38+
]);
39+
40+
$does_work = [
41+
'controllers' => [
42+
'resource' => 'routing.controllers',
43+
],
44+
];
45+
config([
46+
'when@dev' => $does_work,
47+
'when@stage' => $does_work,
48+
]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bug7155;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/** @var \Closure|string $event */
8+
$event = '';
9+
$callback = null;
10+
11+
if ($event instanceof \Closure) {
12+
[$event, $callback] = ['event-name', $event];
13+
}
14+
15+
assertType('string', $event);
16+
assertType('Closure|null', $callback);

0 commit comments

Comments
 (0)