1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00

Using list{0: string, 1?: string} syntax for more precise array key types

Thanks to @orklah's feedback, the `explode()` return type is now much more precise too.

Ref: https://github.com/vimeo/psalm/pull/9016#discussion_r1058458616
This commit is contained in:
Marco Pivetta 2022-12-28 17:48:33 +01:00
parent 6341d7fef0
commit c0c0116809
2 changed files with 13 additions and 13 deletions

View File

@ -731,16 +731,16 @@ function join($separator, array $array = []): string
* $string is lowercase-string * $string is lowercase-string
* ? ( * ? (
* $limit is int<min, -2> * $limit is int<min, -2>
* ? array<empty, empty> * ? list<empty>
* : ( * : (
* $limit is int<0, 1> * $limit is int<0, 1>
* ? array{lowercase-string} * ? list{lowercase-string}
* : ( * : (
* $limit is 2 * $limit is 2
* ? array{0: lowercase-string, 1?: lowercase-string} * ? list{0: lowercase-string, 1?: lowercase-string}
* : ( * : (
* $limit is 3 * $limit is 3
* ? array{0: lowercase-string, 1?: lowercase-string, 2?: lowercase-string} * ? list{0: lowercase-string, 1?: lowercase-string, 2?: lowercase-string}
* : non-empty-list<lowercase-string> * : non-empty-list<lowercase-string>
* ) * )
* ) * )
@ -748,16 +748,16 @@ function join($separator, array $array = []): string
* ) * )
* : ( * : (
* $limit is int<min, -2> * $limit is int<min, -2>
* ? array<empty, empty> * ? list<empty>
* : ( * : (
* $limit is int<0, 1> * $limit is int<0, 1>
* ? array{string} * ? list{string}
* : ( * : (
* $limit is 2 * $limit is 2
* ? array{0: string, 1?: string} * ? list{0: string, 1?: string}
* : ( * : (
* $limit is 3 * $limit is 3
* ? array{0: string, 1?: string, 2?: string} * ? list{0: string, 1?: string, 2?: string}
* : non-empty-list<string> * : non-empty-list<string>
* ) * )
* ) * )

View File

@ -422,7 +422,7 @@ class FunctionCallTest extends TestCase
/** @var string $string */ /** @var string $string */
$elements = explode(" ", $string, -5);', $elements = explode(" ", $string, -5);',
'assertions' => [ 'assertions' => [
'$elements' => 'array<never, never>', '$elements' => 'list<never>',
], ],
], ],
'explodeWithDynamicLimit' => [ 'explodeWithDynamicLimit' => [
@ -433,7 +433,7 @@ class FunctionCallTest extends TestCase
*/ */
$elements = explode(" ", $string, $limit);', $elements = explode(" ", $string, $limit);',
'assertions' => [ 'assertions' => [
'$elements' => 'array{0?: string, 1?: string, 2?: string, ...<int<0, max>, string>}', '$elements' => 'list{0?: string, 1?: string, 2?: string, ...<int<0, max>, string>}',
], ],
], ],
'explodeWithDynamicDelimiter' => [ 'explodeWithDynamicDelimiter' => [
@ -455,7 +455,7 @@ class FunctionCallTest extends TestCase
*/ */
$elements = explode($delim, $string, 2);', $elements = explode($delim, $string, 2);',
'assertions' => [ 'assertions' => [
'$elements' => 'array{0: string, 1?: string}', '$elements' => 'list{0: string, 1?: string}',
], ],
], ],
'explodeWithDynamicDelimiterAndPositiveLimit' => [ 'explodeWithDynamicDelimiterAndPositiveLimit' => [
@ -477,7 +477,7 @@ class FunctionCallTest extends TestCase
*/ */
$elements = explode($delim, $string, -5);', $elements = explode($delim, $string, -5);',
'assertions' => [ 'assertions' => [
'$elements' => 'array<never, never>', '$elements' => 'list<never>',
], ],
], ],
'explodeWithDynamicDelimiterAndLimit' => [ 'explodeWithDynamicDelimiterAndLimit' => [
@ -489,7 +489,7 @@ class FunctionCallTest extends TestCase
*/ */
$elements = explode($delim, $string, $limit);', $elements = explode($delim, $string, $limit);',
'assertions' => [ 'assertions' => [
'$elements' => 'array{0?: string, 1?: string, 2?: string, ...<int<0, max>, string>}', '$elements' => 'list{0?: string, 1?: string, 2?: string, ...<int<0, max>, string>}',
], ],
], ],
'explodeWithDynamicNonEmptyDelimiter' => [ 'explodeWithDynamicNonEmptyDelimiter' => [