mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
use int|string in phpdoc format for array-key (#4645)
This commit is contained in:
parent
f9edf5d7e1
commit
58ddeaafdf
@ -30,4 +30,16 @@ class TArrayKey extends Scalar
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $aliased_classes
|
||||
*/
|
||||
public function toNamespacedString(
|
||||
?string $namespace,
|
||||
array $aliased_classes,
|
||||
?string $this_class,
|
||||
bool $use_phpdoc_format
|
||||
): string {
|
||||
return $use_phpdoc_format ? '(int|string)' : 'array-key';
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +67,7 @@ class TTemplateKeyOf extends TArrayKey
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $aliased_classes
|
||||
*
|
||||
* @param array<string> $aliased_classes
|
||||
*/
|
||||
public function toNamespacedString(
|
||||
?string $namespace,
|
||||
|
@ -965,6 +965,25 @@ class MissingReturnTypeTest extends FileManipulationTest
|
||||
false,
|
||||
true,
|
||||
],
|
||||
'arrayKeyReturn' => [
|
||||
'<?php
|
||||
function scope(array $array) {
|
||||
return (array_keys($array))[0] ?? null;
|
||||
}',
|
||||
'<?php
|
||||
/**
|
||||
* @return (int|string)|null
|
||||
*
|
||||
* @psalm-return array-key|null
|
||||
*/
|
||||
function scope(array $array) {
|
||||
return (array_keys($array))[0] ?? null;
|
||||
}',
|
||||
'7.1',
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
true,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user