-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be smarter about new array keys after assignment
- Loading branch information
1 parent
164241d
commit 6c32371
Showing
5 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Bug9131TypeInference; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param string[] $a | ||
* @param array<string, string> $b | ||
* @param array<int<0, max>, string> $c | ||
* @param array<int<0, max>|string, string> $d | ||
* @return void | ||
*/ | ||
public function doFoo( | ||
array $a, | ||
array $b, | ||
array $c, | ||
array $d | ||
): void | ||
{ | ||
$a[] = 'foo'; | ||
assertType('non-empty-array<string>', $a); | ||
|
||
$b[] = 'foo'; | ||
assertType('non-empty-array<int|string, string>', $b); | ||
|
||
$c[] = 'foo'; | ||
assertType('non-empty-array<int<0, max>, string>', $c); | ||
|
||
$d[] = 'foo'; | ||
assertType('non-empty-array<int<0, max>|string, string>', $d); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Bug9131; | ||
|
||
class A | ||
{ | ||
/** @var array<int<0, max>, string> */ | ||
public array $l = []; | ||
|
||
public function add(string $s): void { | ||
$this->l[] = $s; | ||
} | ||
} |