-
Notifications
You must be signed in to change notification settings - Fork 508
Rework ArrayReplaceFunctionReturnTypeExtension #3958
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
base: 1.12.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ public function arrayReplace($array1, $array2): void | |
*/ | ||
public function arrayReplaceArrayShapes($array1, $array2): void | ||
{ | ||
assertType("non-empty-array<'bar'|'foo', '1'|'2'>", array_replace($array1)); | ||
assertType("non-empty-array<'bar'|'foo', '1'|'2'>", array_replace([], $array1)); | ||
assertType("non-empty-array<'bar'|'foo', '1'|'2'|'4'>", array_replace($array1, $array2)); | ||
assertType("array{foo: '1', bar: '2'}", array_replace($array1)); | ||
assertType("array{foo: '1', bar: '2'}", array_replace([], $array1)); | ||
assertType("array{foo: '1', bar: '4'}", array_replace($array1, $array2)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add another test cases where a bit more mixed keys (strings or ints) would be interesting too 😊 that would also help massively with potential future refactoring |
||
|
||
/** | ||
|
@@ -68,4 +68,38 @@ public function arrayReplaceUnionTypeArrayShapes($array1, $array2): void | |
assertType("array<int, array{bar: '2'}|array{bar: '3'}|array{foo: '1'}|array{foo: '2'}>", array_replace($array1, $array2)); | ||
assertType("array<int, array{bar: '2'}|array{bar: '3'}|array{foo: '1'}|array{foo: '2'}>", array_replace($array2, $array1)); | ||
} | ||
|
||
/** | ||
* @param array{foo: '1', bar: '2'} $array1 | ||
* @param array<string, int> $array2 | ||
* @param array<int, string> $array3 | ||
*/ | ||
public function arrayReplaceArrayShapeAndGeneralArray($array1, $array2, $array3): void | ||
{ | ||
assertType("non-empty-array<string, '1'|'2'|int>", array_replace($array1, $array2)); | ||
assertType("non-empty-array<string, '1'|'2'|int>", array_replace($array2, $array1)); | ||
|
||
assertType("non-empty-array<'bar'|'foo'|int, string>", array_replace($array1, $array3)); | ||
assertType("non-empty-array<'bar'|'foo'|int, string>", array_replace($array3, $array1)); | ||
|
||
assertType("array<int|string, int|string>", array_replace($array2, $array3)); | ||
} | ||
|
||
/** | ||
* @param array{0: 1, 1: 2} $array1 | ||
* @param array{1: 3, 2: 4} $array2 | ||
*/ | ||
public function arrayReplaceNumericKeys($array1, $array2): void | ||
{ | ||
assertType("array{1, 3, 4}", array_replace($array1, $array2)); | ||
} | ||
|
||
/** | ||
* @param list<int> $array1 | ||
* @param list<int> $array2 | ||
*/ | ||
public function arrayReplaceLists($array1, $array2): void | ||
{ | ||
assertType("list<int>", array_replace($array1, $array2)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug12828; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
$a = ['abc' => 'def', 'hello' => 'world']; | ||
assertType("array{abc: 'def', hello: 'world'}", $a); | ||
$a = array_replace($a, ['hello' => 'country']); | ||
assertType("array{abc: 'def', hello: 'country'}", $a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
isFirstClassCallable()
check needed first? ThegetArgs()
got assert notice when there is...
variadic place holder.https://github.com/nikic/PHP-Parser/blob/20b0d55f6655ef2d73d841f6b7d87117a90f9ee2/lib/PhpParser/Node/Expr/CallLike.php#L32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extensions are not called with first-class callables at all.