Skip to content
Open
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 @@ -207,6 +207,25 @@ public function testBug13123(): void
$this->analyse([__DIR__ . '/data/bug-13123.php'], []);
}

#[RequiresPhp('>= 8.5')]
public function testBug14063(): void
{
$this->analyse([__DIR__ . '/data/bug-14063.php'], [
[
'Assign to protected(set) property Bug14063\Obj::$value.',
31,
],
[
'Assign to protected(set) property Bug14063\Obj::$value.',
34,
],
[
'Assign to protected(set) property Bug14063\Base::$value.',
38,
],
]);
}

#[RequiresPhp('>= 8.5')]
public function testCloneWith(): void
{
Expand Down
39 changes: 39 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-14063.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php // lint >= 8.5

declare(strict_types = 1);

namespace Bug14063;

final readonly class Obj
{
public function __construct(public string $value) {}

public function withValue(string $newValue): self
{
return clone($this, ['value' => $newValue]);
}
}

readonly class Base
{
public function __construct(public string $value) {}
}

readonly class Child extends Base
{
public function withValue(string $newValue): self
{
return clone($this, ['value' => $newValue]);
}
}

$obj = new Obj('val');
$newObj = clone($obj, ['value' => 'newVal']);

function test(Obj $obj): void {
clone($obj, ['value' => 'newVal']);
}

function testBase(Base $base): void {
clone($base, ['value' => 'newVal']);
}
Loading