Skip to content
Permalink
Browse files

Fix #2089 - properly coerce arguments

  • Loading branch information...
muglug committed Sep 1, 2019
1 parent 0279c6f commit da1f36b57fd8030b257a87d317b7642ee6008f9c
Showing with 24 additions and 7 deletions.
  1. +8 −7 src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
  2. +16 −0 tests/CallableTest.php
@@ -533,13 +533,14 @@ function (FunctionLikeParameter $p) {
if ($closure_return_types) {
$closure_return_type = new Type\Union($closure_return_types);
if (!$storage->return_type
|| $storage->return_type->hasMixed()
|| TypeAnalyzer::isContainedBy(
$codebase,
$closure_return_type,
$storage->return_type
)
if (($storage->return_type === $storage->signature_return_type)
&& (!$storage->return_type
|| $storage->return_type->hasMixed()
|| TypeAnalyzer::isContainedBy(
$codebase,
$closure_return_type,
$storage->return_type
))
) {
if ($this->function->inferredType) {
/** @var Type\Atomic\TFn */
@@ -1438,6 +1438,22 @@ function (int $x) : int {
);',
'error_message' => 'InvalidArgument',
],
'useClosureDocblockType' => [
'<?php
class A {}
class B extends A {}
function takesA(A $_a) : void {}
function takesB(B $_b) : void {}
$getAButReallyB = /** @return A */ function() {
return new B;
};
takesA($getAButReallyB());
takesB($getAButReallyB());',
'error_message' => 'ArgumentTypeCoercion - src/somefile.php:13:28 - Argument 1 of takesB expects B, parent type A provided',
],
];
}
}

0 comments on commit da1f36b

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