Skip to content
Permalink
Browse files

Fix #1680 - narrow nullable templated matching

  • Loading branch information...
muglug committed May 25, 2019
1 parent 0bcf61d commit 052599192ab53ea522b9d9deb50c7dba2a47a912
Showing with 28 additions and 0 deletions.
  1. +6 −0 src/Psalm/Type/Union.php
  2. +22 −0 tests/Template/TemplateTest.php
@@ -1009,10 +1009,16 @@ public function replaceTemplateTypesWithStandins(
if ($input_type) {
$generic_param = clone $input_type;
if ($this->isNullable() && $generic_param->isNullable()) {

This comment has been minimized.

Copy link
@Ocramius

Ocramius May 25, 2019

Contributor

Question: does a @psalm-param TemplatedParameter|SomeOtherType be assigned Foo, if Foo|SomeOtherType is given?

That's the "more generic" issue around this

$generic_param->removeType('null');
}
$generic_param->setFromDocblock();
if (isset($generic_params[$key][$atomic_type->defining_class ?: ''][0])) {
$existing_depth = $generic_params[$key][$atomic_type->defining_class ?: ''][1] ?? -1;
if ($existing_depth > $depth) {
continue;
}
@@ -2572,6 +2572,28 @@ function getB(int $id, array $mapB): B {
return get(B::class, $mapB, $id);
}'
],
'dontGeneraliseBoundParamWithWiderCallable' => [
'<?php
class C {
public function foo() : void {}
}
/**
* @psalm-template T
* @psalm-param T $t
* @psalm-param callable(?T):void $callable
* @return T
*/
function makeConcrete($t, callable $callable) {
$callable(rand(0, 1) ? $t : null);
return $t;
}
$c = makeConcrete(new C(), function (?C $c) : void {});',
[
'$c' => 'C',
]
],
];
}

0 comments on commit 0525991

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