Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,13 @@ public function testBug8068(): void
]);
}

public function testBug6243(): void
{
if (PHP_VERSION_ID < 704000) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->analyse([__DIR__ . '/data/bug-6243.php'], []);
}

}
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-6243.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php // lint >= 7.4

namespace Bug6243;

class Foo
{
/** @var list<string>|(\ArrayAccess<int, string>&iterable<int, string>) */
private iterable $values;

/**
* @param list<string> $values
*/
public function update(array $values): void {
foreach ($this->values as $key => $_) {
unset($this->values[$key]);
}

foreach ($values as $value) {
$this->values[] = $value;
}
}
}
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Classes/InstantiationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,18 @@ public function testBug7594(): void
$this->analyse([__DIR__ . '/data/bug-7594.php'], []);
}

public function testBug3311a(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->analyse([__DIR__ . '/data/bug-3311a.php'], [
[
'Parameter #1 $bar of class Bug3311a\Foo constructor expects list<string>, array{1: \'baz\'} given.',
24,
],
]);
}

}
25 changes: 25 additions & 0 deletions tests/PHPStan/Rules/Classes/data/bug-3311a.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1); // lint >= 7.4

namespace Bug3311a;

final class Foo
{
/**
* @var array<int, string>
* @psalm-var list<string>
*/
public array $bar = [];

/**
* @param array<int, string> $bar
* @psalm-param list<string> $bar
*/
public function __construct(array $bar)
{
$this->bar = $bar;
}
}

function () {
$instance = new Foo([1 => 'baz']);
};
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,19 @@ public function testIntegerRangesAndConstants(): void
]);
}

public function testBug3311b(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-3311b.php'], [
[
'Property Bug3311b\Foo::$bar (list<string>) does not accept non-empty-array<int<0, max>, string>.',
16,
],
]);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-3311b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1); // lint >= 7.4

namespace Bug3311b;

final class Foo
{
/**
* @var array<int, string>
* @psalm-var list<string>
*/
public array $bar = [];
}

function () {
$instance = new Foo;
$instance->bar[1] = 'baz';
};