Skip to content
Permalink
Browse files

Fix #2432 - narrow template type after is_object check

  • Loading branch information
muglug committed Dec 9, 2019
1 parent 432c291 commit 517aaac85147c8e93cd2ff88584baad12ca81e7c
Showing with 23 additions and 1 deletion.
  1. +9 −1 src/Psalm/Internal/Type/AssertionReconciler.php
  2. +14 −0 tests/Template/FunctionTemplateTest.php
@@ -1247,9 +1247,17 @@ private static function reconcileObject(
} elseif ($type instanceof TCallable) {
$object_types[] = new Type\Atomic\TCallableObject();
$did_remove_type = true;
} elseif ($type instanceof TTemplateParam) {
} elseif ($type instanceof TTemplateParam
&& $type->as->isMixed()
) {
$type = clone $type;
$type->as = Type::getObject();
$object_types[] = $type;
$did_remove_type = true;
} elseif ($type instanceof TTemplateParam
&& $type->as->hasObject()
) {
$object_types[] = $type;
} else {
$did_remove_type = true;
}
@@ -842,6 +842,20 @@ function example(array $array): array {
return $array;
}',
],
'narrowTemplateTypeWithIsObject' => [
'<?php
function takesObject(object $object): void {}
/**
* @template T as mixed
* @param T $value
*/
function example($value): void {
if (is_object($value)) {
takesObject($value);
}
}'
],
];
}

0 comments on commit 517aaac

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