Skip to content
Permalink
Browse files

Fix #2577 - fix list cast to array

  • Loading branch information
muglug committed Jan 11, 2020
1 parent 2ae85f7 commit 85966d8a216317a378e5928dfd373e7856faff7e
Showing with 17 additions and 3 deletions.
  1. +5 −3 src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
  2. +12 −0 tests/ArrayAssignmentTest.php
@@ -55,6 +55,7 @@
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TList;
use Psalm\Type\Atomic\TMixed;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNull;
@@ -635,9 +636,10 @@ public static function analyze(
$permissible_atomic_types[] = new ObjectLike([new Type\Union([$type])]);
} elseif ($type instanceof TNull) {
$permissible_atomic_types[] = new TArray([Type::getEmpty(), Type::getEmpty()]);
} elseif ($type instanceof TArray) {
$permissible_atomic_types[] = clone $type;
} elseif ($type instanceof ObjectLike) {
} elseif ($type instanceof TArray
|| $type instanceof TList
|| $type instanceof ObjectLike
) {
$permissible_atomic_types[] = clone $type;
} else {
$all_permissible = false;
@@ -1023,6 +1023,18 @@ public function getPosters($commenter, $numToGet=10) {
'$b' => 'array<empty, empty>',
],
],
'coerceListToArray' => [
'<?php
/**
* @param list<int> $_bar
*/
function foo(array $_bar) : void {}
/**
* @param list<int> $bar
*/
function baz(array $bar) : void { foo((array) $bar); }',
],
'getOnCoercedArray' => [
'<?php
function getArray() : array {

0 comments on commit 85966d8

Please sign in to comment.
You can’t perform that action at this time.