mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
add tests for int-like string array keys
This commit is contained in:
parent
63ea4de701
commit
1b91f566c4
@ -130,36 +130,36 @@ class ArrayKeysTest extends TestCase
|
||||
* @psalm-type TAlias = 123
|
||||
*/
|
||||
class a {}
|
||||
|
||||
|
||||
/**
|
||||
* @psalm-import-type TAlias from a
|
||||
* @template TKey as array-key
|
||||
* @template TValue as array-key
|
||||
* @template T as array<TKey, TValue>
|
||||
*
|
||||
*
|
||||
* @template TOrig as a|b
|
||||
* @template TT as class-string<TOrig>
|
||||
*
|
||||
*
|
||||
* @template TBool as bool
|
||||
*/
|
||||
class b {
|
||||
/**
|
||||
* @var array<TAlias, int>
|
||||
/**
|
||||
* @var array<TAlias, int>
|
||||
*/
|
||||
private array $a = [123 => 123];
|
||||
|
||||
|
||||
/** @var array<value-of<T>, int> */
|
||||
public array $c = [];
|
||||
|
||||
|
||||
/** @var array<key-of<T>, int> */
|
||||
public array $d = [];
|
||||
|
||||
|
||||
/** @var array<TT, int> */
|
||||
public array $e = [];
|
||||
|
||||
|
||||
/** @var array<key-of<array<int, string>>, int> */
|
||||
private array $f = [123 => 123];
|
||||
|
||||
|
||||
/** @var array<value-of<array<int, string>>, int> */
|
||||
private array $g = ["test" => 123];
|
||||
|
||||
@ -173,7 +173,7 @@ class ArrayKeysTest extends TestCase
|
||||
return $v ? ["a" => 123] : [123 => 123];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @var b<"testKey", "testValue", array<"testKey", "testValue">, b, class-string<b>, true> */
|
||||
$b = new b;
|
||||
$b->d["testKey"] = 123;
|
||||
@ -183,6 +183,26 @@ class ArrayKeysTest extends TestCase
|
||||
//$b->e["b"] = 123;
|
||||
',
|
||||
],
|
||||
'intStringKeyAsInt' => [
|
||||
'code' => '<?php
|
||||
$a = ["15" => "a"];
|
||||
$b = ["15.7" => "a"];
|
||||
// since PHP 8 this is_numeric but will not be int key
|
||||
$c = ["15 " => "a"];
|
||||
$d = ["-15" => "a"];
|
||||
// see https://github.com/php/php-src/issues/9029#issuecomment-1186226676
|
||||
$e = ["+15" => "a"];
|
||||
$f = ["015" => "a"];
|
||||
',
|
||||
'assertions' => [
|
||||
'$a===' => "array{15: 'a'}",
|
||||
'$b===' => "array{'15.7': 'a'}",
|
||||
'$c===' => "array{'15 ': 'a'}",
|
||||
'$d===' => "array{-15: 'a'}",
|
||||
'$e===' => "array{'+15': 'a'}",
|
||||
'$f===' => "array{'015': 'a'}",
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user