mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Improve ergonomics of array assignment
This commit is contained in:
parent
2fe8717639
commit
7dfa37beb2
@ -428,7 +428,7 @@ class TypeCombination
|
||||
$allow_mixed_union
|
||||
);
|
||||
|
||||
if ($allow_mixed_union || !$generic_type_params[1]->isMixed()) {
|
||||
if (!$generic_type_params[1]->isMixed()) {
|
||||
$generic_type_params[1] = Type::combineUnionTypes(
|
||||
$generic_type_params[1],
|
||||
$objectlike_generic_type,
|
||||
|
@ -1402,9 +1402,26 @@ class ArrayAssignmentTest extends TestCase
|
||||
$arr["hello"]["goodbye"] = 5;
|
||||
}',
|
||||
[
|
||||
'$arr' => 'array<array-key, array{goodbye: int}|mixed>',
|
||||
'$arr' => 'array<array-key, mixed>',
|
||||
]
|
||||
],
|
||||
'dontUpdateMixedArrayWithStringKey' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
||||
/**
|
||||
* @psalm-suppress MixedArgument
|
||||
*/
|
||||
function run1(array $arguments): void {
|
||||
if (rand(0, 1)) {
|
||||
$arguments["c"] = new A();
|
||||
}
|
||||
|
||||
if ($arguments["b"]) {
|
||||
echo $arguments["b"];
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -383,7 +383,7 @@ class TypeCombinationTest extends TestCase
|
||||
],
|
||||
],
|
||||
'combineMixedArrayWithObjectLike' => [
|
||||
'array<array-key, int|mixed>',
|
||||
'array<array-key, mixed>',
|
||||
[
|
||||
'array{a: int}',
|
||||
'array',
|
||||
@ -523,21 +523,28 @@ class TypeCombinationTest extends TestCase
|
||||
],
|
||||
],
|
||||
'combineCallableArrayAndArray' => [
|
||||
'array<array-key, mixed|string>',
|
||||
'array<array-key, mixed>',
|
||||
[
|
||||
'callable-array{class-string, string}',
|
||||
'array',
|
||||
],
|
||||
],
|
||||
'combineObjectLikeArrayAndArray' => [
|
||||
'combineGenericArrayAndMixedArray' => [
|
||||
'array<array-key, int|mixed>',
|
||||
[
|
||||
'array<string, int>',
|
||||
'array<array-key, mixed>',
|
||||
],
|
||||
],
|
||||
'combineObjectLikeArrayAndArray' => [
|
||||
'array<array-key, mixed>',
|
||||
[
|
||||
'array{hello: int}',
|
||||
'array<array-key, mixed>',
|
||||
],
|
||||
],
|
||||
'combineObjectLikeArrayAndNestedArray' => [
|
||||
'array<array-key, array{goodbye: int}|mixed>',
|
||||
'array<array-key, mixed>',
|
||||
[
|
||||
'array{hello: array{goodbye: int}}',
|
||||
'array<array-key, mixed>',
|
||||
|
@ -139,7 +139,7 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
|
||||
'iterableToArray' => ['array<int, int>', 'array', 'iterable<int, int>'],
|
||||
'iterableToTraversable' => ['Traversable<int, int>', 'Traversable', 'iterable<int, int>'],
|
||||
'callableToCallableArray' => ['callable-array{0: class-string|object, 1: string}', 'array', 'callable'],
|
||||
'callableOrArrayToCallableArray' => ['array<array-key, mixed|object|string>', 'array', 'callable|array'],
|
||||
'callableOrArrayToCallableArray' => ['array<array-key, mixed>', 'array', 'callable|array'],
|
||||
'traversableToIntersection' => ['Countable&Traversable', 'Traversable', 'Countable'],
|
||||
'iterableWithoutParamsToTraversableWithoutParams' => ['Traversable', '!array', 'iterable'],
|
||||
'iterableWithParamsToTraversableWithParams' => ['Traversable<int, string>', '!array', 'iterable<int, string>'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user