Skip to content

Commit

Permalink
Gh 1660 (#1661)
Browse files Browse the repository at this point in the history
* Failing test

* Fix missing key
  • Loading branch information
dantleech committed May 26, 2022
1 parent c607643 commit ed4d3c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Phpactor\WorseReflection\Core\Type\AggregateType;
use Phpactor\WorseReflection\Core\Type\ArrayLiteral;
use Phpactor\WorseReflection\Core\Type\ArrayShapeType;
use Phpactor\WorseReflection\Core\Type\ArrayType;
use Phpactor\WorseReflection\Core\Type\Literal;
use Phpactor\WorseReflection\Core\Type\MissingType;
use Phpactor\WorseReflection\Core\Type\StringType;
Expand Down Expand Up @@ -170,6 +171,11 @@ private function walkSubscriptExpression(NodeContextResolver $resolver, Frame $f
$accessType = $resolver->resolveNode($frame, $leftOperand->accessExpression)->type();

if (!$accessType instanceof Literal) {
$frame->locals()->add(
$variable->withType(
new ArrayType(TypeFactory::undefined(), $rightContext->type())
)
);
return;
}

Expand Down Expand Up @@ -209,7 +215,7 @@ private function hasMissingTokens(AssignmentExpression $node): bool
return true;
}
}

return false;
}

Expand All @@ -223,18 +229,18 @@ private function walkArrayElements(array $elements, Node $leftOperand, Type $typ
if (!$element instanceof ArrayElement) {
continue;
}

$index++;
$elementValue = $element->elementValue;
if (!$elementValue instanceof Variable) {
continue;
}

/** @phpstan-ignore-next-line */
if (null === $elementValue || null === $elementValue->name) {
continue;
}

$varName = NodeUtil::nameFromTokenOrNode($leftOperand, $elementValue->name);

$variableContext = NodeContextFactory::create(
Expand Down
10 changes: 10 additions & 0 deletions lib/WorseReflection/Tests/Inference/assignment/unknown_key.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php


$results = [];
foreach ($this->analyser->analyse($input->getArgument(self::ARG_PATH)) as $file => $diagnostics) {
$results[$file] = 1234;
}

wrAssertType('array<<missing>,1234>', $results);

0 comments on commit ed4d3c4

Please sign in to comment.