Skip to content
Permalink
Browse files

Fix #1886 - allow empty array to be coerced to a mixed one

  • Loading branch information...
muglug committed Jul 5, 2019
1 parent 11fbc15 commit b4f03abca627bf99706c41d109a6d15c6a0cb0b3
Showing with 28 additions and 0 deletions.
  1. +1 −0 src/Psalm/Internal/Analyzer/TypeAnalyzer.php
  2. +10 −0 src/Psalm/Type/Union.php
  3. +17 −0 tests/Template/ClassTemplateTest.php
@@ -1789,6 +1789,7 @@ private static function isMatchingTypeContainedBy(
&& !$container_param->hasTemplate()
&& !$input_param->hasTemplate()
&& !$input_param->hasLiteralValue()
&& !$input_param->hasEmptyArray()
) {
$input_storage = $codebase->classlike_storage_provider->get($input_type_part->value);
@@ -569,6 +569,16 @@ public function hasArray()
return isset($this->types['array']);
}
/**
* @return bool
*/
public function hasEmptyArray()
{
return isset($this->types['array'])
&& $this->types['array'] instanceof Atomic\TArray
&& $this->types['array']->type_params[1]->isEmpty();
}
/**
* @return bool
*/
@@ -1601,6 +1601,23 @@ function test(): TestPromise {
return new TestPromise(true);
}',
],
'classTemplatedPropertyEmptyAssignment' => [
'<?php
/** @template T */
class Foo {
/** @param \Closure():T $closure */
public function __construct($closure) {}
}
class Bar {
/** @var Foo<array> */
private $FooArray;
public function __construct() {
$this->FooArray = new Foo(function(): array { return []; });
}
}',
],
];
}

0 comments on commit b4f03ab

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