1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +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
* ? (
* $limit is int<min, -2>
* ? array<empty, empty>
* ? list<empty>
* : (
* $limit is int<0, 1>
* ? array{lowercase-string}
* ? list{lowercase-string}
* : (
* $limit is 2
* ? array{0: lowercase-string, 1?: lowercase-string}
* ? list{0: lowercase-string, 1?: lowercase-string}
* : (
* $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>
* )
* )
@ -748,16 +748,16 @@ function join($separator, array $array = []): string
* )
* : (
* $limit is int<min, -2>
* ? array<empty, empty>
* ? list<empty>
* : (
* $limit is int<0, 1>
* ? array{string}
* ? list{string}
* : (
* $limit is 2
* ? array{0: string, 1?: string}
* ? list{0: string, 1?: string}
* : (
* $limit is 3
* ? array{0: string, 1?: string, 2?: string}
* ? list{0: string, 1?: string, 2?: string}
* : non-empty-list<string>
* )
* )

View File

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