Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong assignation to intersection including ArrayAccess not being reported #843

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ public function testRuleWithNullsafeVariant(): void
]);
}

public function testRuleOnArrayAccessIntersection(): void
{
$this->analyse([__DIR__ . '/data/offset-access-value-assignment-on-array-access-intersection.php'], [
[
'ArrayAccess<int, string> does not accept int.',
15,
],
[
'ArrayAccess<int, string>&Countable&iterable<int, string> does not accept int.',
16,
],
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace OffsetAccessValueAssignmentOnArrayAccessIntersection;

class Foo
{
/** @var \ArrayAccess<int, string> */
private $collection1;

/** @var \ArrayAccess<int, string>&\Countable&iterable<int, string> */
private $collection2;

public function foo(): void
{
$this->collection1[] = 1;
$this->collection2[] = 2;
}
}