mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #7967 from hirokinoue/fix_return_type
Improve @return annotation for implode() so that it can handle non-empty-array of non-empty-strings case
This commit is contained in:
commit
894e4e4c02
@ -582,8 +582,13 @@ function rtrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
|
||||
* : non-empty-string
|
||||
* )
|
||||
* : string)
|
||||
* : ($array is non-empty-array
|
||||
* ? ($array is array<non-empty-literal-string|non-empty-string>
|
||||
* ? ($array is array<non-empty-literal-string> ? non-empty-literal-string : non-empty-string)
|
||||
* : string
|
||||
* )
|
||||
* : string)
|
||||
* )
|
||||
*
|
||||
* @psalm-flow ($separator) -> return
|
||||
* @psalm-flow ($array) -(array-fetch)-> return
|
||||
@ -604,8 +609,13 @@ function implode($separator, array $array = []) : string {}
|
||||
* : non-empty-string
|
||||
* )
|
||||
* : string)
|
||||
* : ($array is non-empty-array
|
||||
* ? ($array is array<non-empty-literal-string|non-empty-string>
|
||||
* ? ($array is array<non-empty-literal-string> ? non-empty-literal-string : non-empty-string)
|
||||
* : string
|
||||
* )
|
||||
* : string)
|
||||
* )
|
||||
*
|
||||
* @psalm-flow ($separator) -> return
|
||||
* @psalm-flow ($array) -(array-fetch)-> return
|
||||
|
@ -1055,6 +1055,31 @@ class ArrayFunctionCallTest extends TestCase
|
||||
'$b===' => 'non-empty-literal-string',
|
||||
]
|
||||
],
|
||||
'implodeArrayOfNonEmptyStringAndEmptyString' => [
|
||||
'<?php
|
||||
class Foo {
|
||||
const DIR = __DIR__;
|
||||
}
|
||||
$l = ["a", "b"];
|
||||
$k = [Foo::DIR];
|
||||
$a = implode("", $l);
|
||||
$b = implode("", $k);',
|
||||
[
|
||||
'$a===' => 'non-empty-literal-string',
|
||||
'$b===' => 'non-empty-string',
|
||||
]
|
||||
],
|
||||
'implodeEmptyArrayAndString' => [
|
||||
'<?php
|
||||
$l = [""];
|
||||
$k = [];
|
||||
$a = implode("", $l);
|
||||
$b = implode("", $k);',
|
||||
[
|
||||
'$a===' => 'string',
|
||||
'$b===' => 'string',
|
||||
]
|
||||
],
|
||||
'key' => [
|
||||
'<?php
|
||||
$a = ["one" => 1, "two" => 3];
|
||||
|
Loading…
x
Reference in New Issue
Block a user