From ddc97fb3ec31b007787b3341435317b739997bc9 Mon Sep 17 00:00:00 2001 From: WildEgo Date: Wed, 22 May 2024 11:59:24 +0100 Subject: [PATCH] add: Basic match implementation. --- src/Infer/Scope/Scope.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Infer/Scope/Scope.php b/src/Infer/Scope/Scope.php index 13eb86ed..c754eba2 100644 --- a/src/Infer/Scope/Scope.php +++ b/src/Infer/Scope/Scope.php @@ -60,6 +60,17 @@ public function getType(Node $node): Type ]); } + if ($node instanceof Node\Expr\Match_) { + return match (get_class($node->cond)) { + Node\Expr\ArrayDimFetch::class, Node\Expr\Variable::class => Union::wrap( + collect($node->arms) + ->map(fn (Node\MatchArm $arm) => $this->getType($arm->body)) + ->toArray() + ), + default => new UnknownType('Cannot infer type of property fetch: not supported yet.'), + }; + } + if ($node instanceof Node\Expr\ClassConstFetch) { return (new ClassConstFetchTypeGetter)($node, $this); }