From e822ec7541398c8f3895d11520120071fd31536a Mon Sep 17 00:00:00 2001 From: Brown Date: Wed, 9 Oct 2019 12:49:31 -0400 Subject: [PATCH] Unsetting list elements should turn to an array --- src/Psalm/Internal/Analyzer/StatementsAnalyzer.php | 7 +++++++ tests/ArrayAccessTest.php | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 4522b5bec..0591bf653 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -1270,6 +1270,13 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource $root_type->addType( new Type\Atomic\TMixed() ); + } elseif ($atomic_root_type instanceof Type\Atomic\TList) { + $root_type->addType( + new Type\Atomic\TArray([ + Type::getInt(), + $atomic_root_type->type_param + ]) + ); } } diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index db15f41b7..433d3ea0b 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -953,6 +953,19 @@ class ArrayAccessTest extends TestCase $array[$a] = "b";', 'error_message' => 'UndefinedGlobalVariable', ], + 'unsetListElementShouldChangeToArray' => [ + ' $arr + * @return list + */ + function takesList(array $arr) : array { + unset($arr[0]); + + return $arr; + }', + 'error_message' => 'LessSpecificReturnStatement', + ], ]; } }