vimeo/psalm

`array_splice` type and side effects not handled properly

Open

#8,202 创建于 2022年6月29日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)PHP (668 fork)batch import
Help wantedeasy problemsenhancementgood first issue

仓库指标

Star
 (5,369 star)
PR 合并指标
 (平均合并 3天 12小时) (30 天内合并 5 个 PR)

描述

I recently updated to 5.0.0-beta1 for a PHP 8.1-based project, and now I'm getting an error reported with array_splice().

https://psalm.dev/r/367fd63316

I'm having PHP take a chunk of items off an array in C code, so it takes fewer interpreter steps to get the work done. But Psalm doesn't seem to realize that the return value from splice matches the input type (including preserving string keys), or that the splice changes the array it is given.

Building the equivalent with a for-loop and array_shift() is accepted, or else there is an error in my own understanding.

I'm unsure when I last checked this exact code in Psalm 4.x. The exact version I'm using reports itself as Psalm 5.0.0-beta1@f960d71b7e8dccb0815bce28a22a33ce5410e361.

贡献者指南