mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #2787 - make accessing undefined objectlike key an error
This commit is contained in:
parent
9f13341ef9
commit
db17c85dd6
@ -891,7 +891,7 @@ class ArrayFetchAnalyzer
|
||||
|
||||
$array_access_type = clone $type->previous_value_type;
|
||||
} else {
|
||||
if ($type->sealed) {
|
||||
if ($type->sealed || !$context->inside_isset) {
|
||||
$object_like_keys = array_keys($type->properties);
|
||||
|
||||
if (count($object_like_keys) === 1) {
|
||||
|
@ -1405,7 +1405,7 @@ class TypeAnalyzer
|
||||
|| $container_type_part instanceof THtmlEscapedString)
|
||||
) {
|
||||
if ($input_type_part instanceof TLiteralString) {
|
||||
return is_numeric($input_type_part->value);
|
||||
return \is_numeric($input_type_part->value);
|
||||
}
|
||||
if ($atomic_comparison_result) {
|
||||
$atomic_comparison_result->type_coerced = true;
|
||||
|
@ -27,7 +27,7 @@ class OffsetShifterVisitor extends PhpParser\NodeVisitorAbstract implements PhpP
|
||||
*/
|
||||
public function enterNode(PhpParser\Node $node)
|
||||
{
|
||||
/** @var array{startFilePos: int, endFilePos: int} */
|
||||
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
|
||||
$attrs = $node->getAttributes();
|
||||
|
||||
if ($cs = $node->getComments()) {
|
||||
|
@ -66,7 +66,7 @@ class PartialParserVisitor extends PhpParser\NodeVisitorAbstract implements PhpP
|
||||
*/
|
||||
public function enterNode(PhpParser\Node $node, &$traverseChildren = true)
|
||||
{
|
||||
/** @var array{startFilePos: int, endFilePos: int} */
|
||||
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
|
||||
$attrs = $node->getAttributes();
|
||||
|
||||
if ($cs = $node->getComments()) {
|
||||
|
@ -1144,6 +1144,18 @@ class ArrayAccessTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'TypeDoesNotContainType',
|
||||
],
|
||||
'undefinedObjectLikeArrayOffset' => [
|
||||
'<?php
|
||||
class Example {
|
||||
/**
|
||||
* @param array{a: string, b: int} $context
|
||||
*/
|
||||
function foo(array $context): void {
|
||||
$context["c"];
|
||||
}
|
||||
}',
|
||||
'error_message' => 'InvalidArrayOffset'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user