From 7c904b60e8148024f9f2d0645568a482c6e79432 Mon Sep 17 00:00:00 2001 From: azjezz Date: Mon, 6 Jul 2020 19:30:42 +0100 Subject: [PATCH] [Arr] group_by: throw when $key_fun returns a non-arraykey type --- src/Psl/Arr/group_by.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Psl/Arr/group_by.php b/src/Psl/Arr/group_by.php index e829c09..b5196f5 100644 --- a/src/Psl/Arr/group_by.php +++ b/src/Psl/Arr/group_by.php @@ -45,6 +45,8 @@ function group_by(iterable $values, callable $key_func): array continue; } + Psl\invariant(is_arraykey($key), 'Expected $key_func to return a value of type array-key, value of type (%s) returned.', gettype($key)); + /** @psalm-var Tk $key */ $result[$key] = $result[$key] ?? []; $result[$key][] = $value; }