Skip to content

Commit

Permalink
add: Basic match implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
WildEgo committed May 22, 2024
1 parent dbbf57b commit ddc97fb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Infer/Scope/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ddc97fb

Please sign in to comment.