mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #3061 - prevent array_key_exists from completely changing type
This commit is contained in:
parent
af4a7cabe9
commit
ecac9d56c0
@ -1658,7 +1658,13 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
||||
$const_type_atomic = $const_type_atomic->getGenericArrayType();
|
||||
}
|
||||
|
||||
return clone $const_type_atomic->type_params[0];
|
||||
if (TypeAnalyzer::isContainedBy(
|
||||
$codebase,
|
||||
$const_type_atomic->type_params[0],
|
||||
$existing_var_type
|
||||
)) {
|
||||
return clone $const_type_atomic->type_params[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1324,6 +1324,24 @@ class ArrayFunctionCallTest extends TestCase
|
||||
return $elements;
|
||||
}'
|
||||
],
|
||||
'arrayKeyExistsShoudldNotModifyIntType' => [
|
||||
'<?php
|
||||
class HttpError {
|
||||
const ERRS = [
|
||||
403 => "a",
|
||||
404 => "b",
|
||||
500 => "c"
|
||||
];
|
||||
}
|
||||
|
||||
function init(string $code) : string {
|
||||
if (array_key_exists($code, HttpError::ERRS)) {
|
||||
return $code;
|
||||
}
|
||||
|
||||
return "";
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user