Skip to content
Permalink
Browse files

Fix new template class array key coercion to mixed - when we don’t kn…

…ow, assume bottom type
  • Loading branch information...
muglug committed Apr 26, 2019
1 parent 82e0bca commit 59e53acd562f014fd90f25e4571f2855af2a0557
@@ -364,7 +364,7 @@ public static function analyze(
? explode('::', $declaring_method_id)[0]
: $fq_class_name;
foreach ($storage->template_types as $template_name => $_) {
foreach ($storage->template_types as $template_name => $base_type) {
if (isset($found_generic_params[$template_name][$fq_class_name])) {
$generic_param_types[] = $found_generic_params[$template_name][$fq_class_name][0];
} elseif ($storage->template_type_extends && $found_generic_params) {
@@ -375,7 +375,7 @@ public static function analyze(
$found_generic_params
);
} else {
$generic_param_types[] = Type::getMixed();
$generic_param_types[] = array_values($base_type)[0][0];
}
}
}
@@ -2070,6 +2070,34 @@ public function foo($t): void {
}
}'
],
'allowTemplateParamsToCoerceToMinimumTypes' => [
'<?php
/**
* @psalm-template TKey of array-key
* @psalm-template T
*/
class ArrayCollection
{
/**
* @var array<TKey,T>
*/
private $elements;
/**
* @param array<TKey,T> $elements
*/
public function __construct(array $elements = [])
{
$this->elements = $elements;
}
}
/** @psalm-suppress MixedArgument */
$c = new ArrayCollection($_GET["a"]);',
[
'$c' => 'ArrayCollection<array-key, mixed>',
],
],
];
}

0 comments on commit 59e53ac

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