mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #709 - detect intersection template matches a bit better
This commit is contained in:
parent
77d4629896
commit
3380de16a2
@ -601,10 +601,26 @@ class Union
|
|||||||
$generic_params[$key]->setFromDocblock();
|
$generic_params[$key]->setFromDocblock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$matching_atomic_type = null;
|
||||||
|
|
||||||
|
if ($input_type) {
|
||||||
|
foreach ($input_type->types as $input_key => $atomic_input_type) {
|
||||||
|
if ($input_key === $key) {
|
||||||
|
$matching_atomic_type = $atomic_input_type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($input_key, $key . '&') === 0) {
|
||||||
|
$matching_atomic_type = $atomic_input_type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$atomic_type->replaceTemplateTypesWithStandins(
|
$atomic_type->replaceTemplateTypesWithStandins(
|
||||||
$template_types,
|
$template_types,
|
||||||
$generic_params,
|
$generic_params,
|
||||||
isset($input_type->types[$key]) ? $input_type->types[$key] : null
|
$matching_atomic_type
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,6 +471,35 @@ class TemplateTest extends TestCase
|
|||||||
],
|
],
|
||||||
'error_levels' => ['MixedAssignment', 'MixedArgument'],
|
'error_levels' => ['MixedAssignment', 'MixedArgument'],
|
||||||
],
|
],
|
||||||
|
'intersectionTemplatedTypes' => [
|
||||||
|
'<?php
|
||||||
|
namespace NS;
|
||||||
|
use Countable;
|
||||||
|
|
||||||
|
/** @template T */
|
||||||
|
class Collection
|
||||||
|
{
|
||||||
|
/** @psalm-var iterable<T> */
|
||||||
|
private $data;
|
||||||
|
|
||||||
|
/** @psalm-param iterable<T> $data */
|
||||||
|
public function __construct(iterable $data) {
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Item {}
|
||||||
|
/** @psalm-param Collection<Item> $c */
|
||||||
|
function takesCollectionOfItems(Collection $c): void {}
|
||||||
|
|
||||||
|
/** @psalm-var iterable<Item> $data2 */
|
||||||
|
$data2 = [];
|
||||||
|
takesCollectionOfItems(new Collection($data2));
|
||||||
|
|
||||||
|
/** @psalm-var iterable<Item>&Countable $data */
|
||||||
|
$data = [];
|
||||||
|
takesCollectionOfItems(new Collection($data));',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user