Skip to content

Commit 76e1258

Browse files
committed
test array accessories and HasOffset*Type
1 parent 9e815d3 commit 76e1258

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/PHPStan/Analyser/nsrt/bug-12393b.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,53 @@ public function doFoo(array $arr): void
484484
}
485485

486486
}
487+
488+
class FooArray
489+
{
490+
public array $foo;
491+
492+
/**
493+
* @param non-empty-array $arr
494+
*/
495+
public function doFoo(array $arr): void
496+
{
497+
$this->foo = $arr;
498+
assertType('non-empty-array', $this->foo);
499+
500+
if (array_key_exists('foo', $arr)) {
501+
$this->foo = $arr;
502+
assertType("non-empty-array&hasOffset('foo')", $this->foo);
503+
}
504+
505+
if (array_key_exists('foo', $arr) && $arr['foo'] === 'bar') {
506+
$this->foo = $arr;
507+
assertType("non-empty-array&hasOffsetValue('foo', 'bar')", $this->foo);
508+
}
509+
}
510+
511+
}
512+
513+
class FooList
514+
{
515+
public array $foo;
516+
517+
/**
518+
* @param non-empty-list $list
519+
*/
520+
public function doFoo(array $list): void
521+
{
522+
$this->foo = $list;
523+
assertType('non-empty-list', $this->foo);
524+
525+
if (array_key_exists(3, $list)) {
526+
$this->foo = $list;
527+
assertType("non-empty-list&hasOffset(3)", $this->foo);
528+
}
529+
530+
if (array_key_exists(3, $list) && is_string($list[3])) {
531+
$this->foo = $list;
532+
assertType("non-empty-list&hasOffsetValue(3, string)", $this->foo);
533+
}
534+
}
535+
536+
}

0 commit comments

Comments
 (0)