mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #814 - remove literal types when removing base key
This commit is contained in:
parent
3891b08fc2
commit
45a94af015
@ -399,6 +399,21 @@ class Union
|
||||
$this->id = null;
|
||||
|
||||
return true;
|
||||
} elseif ($type_string === 'string' && $this->literal_string_types) {
|
||||
foreach ($this->literal_string_types as $literal_key => $_) {
|
||||
unset($this->types[$literal_key]);
|
||||
}
|
||||
$this->literal_string_types = [];
|
||||
} elseif ($type_string === 'int' && $this->literal_int_types) {
|
||||
foreach ($this->literal_int_types as $literal_key => $_) {
|
||||
unset($this->types[$literal_key]);
|
||||
}
|
||||
$this->literal_int_types = [];
|
||||
} elseif ($type_string === 'float' && $this->literal_float_types) {
|
||||
foreach ($this->literal_float_types as $literal_key => $_) {
|
||||
unset($this->types[$literal_key]);
|
||||
}
|
||||
$this->literal_float_types = [];
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -369,6 +369,42 @@ class ValueTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'removeLiteralStringForNotIsString' => [
|
||||
'<?php
|
||||
function takesInt(int $i) : void {}
|
||||
|
||||
$f = ["a", "b", "c"];
|
||||
$f[rand(0, 2)] = 5;
|
||||
|
||||
$i = rand(0, 2);
|
||||
if (isset($f[$i]) && !is_string($f[$i])) {
|
||||
takesInt($f[$i]);
|
||||
}'
|
||||
],
|
||||
'removeLiteralIntForNotIsInt' => [
|
||||
'<?php
|
||||
function takesString(string $i) : void {}
|
||||
|
||||
$f = [0, 1, 2];
|
||||
$f[rand(0, 2)] = "hello";
|
||||
|
||||
$i = rand(0, 2);
|
||||
if (isset($f[$i]) && !is_int($f[$i])) {
|
||||
takesString($f[$i]);
|
||||
}'
|
||||
],
|
||||
'removeLiteralFloatForNotIsFloat' => [
|
||||
'<?php
|
||||
function takesString(string $i) : void {}
|
||||
|
||||
$f = [1.1, 1.2, 1.3];
|
||||
$f[rand(0, 2)] = "hello";
|
||||
|
||||
$i = rand(0, 2);
|
||||
if (isset($f[$i]) && !is_float($f[$i])) {
|
||||
takesString($f[$i]);
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user