Skip to content

Commit

Permalink
Warn about more generic callables
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 14, 2019
1 parent ce2e5b2 commit 1a92e98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Psalm/Internal/Analyzer/TypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,21 @@ private static function isMatchingTypeContainedBy(
}
}

if ($container_type_part instanceof Type\Atomic\TCallable
&& $input_type_part instanceof Type\Atomic\TCallable
) {
if (self::compareCallable(
$codebase,
$input_type_part,
$container_type_part,
$atomic_comparison_result,
$all_types_contain
) === false
) {
return false;
}
}

if ($container_type_part instanceof TList
&& $input_type_part instanceof ObjectLike
) {
Expand Down
12 changes: 12 additions & 0 deletions tests/CallableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,18 @@ function map2(callable $mapper): void {}
map2("foo");',
'error_message' => 'MismatchingDocblockParamType',
],
'moreSpecificCallable' => [
'<?php
/** @param callable(string):void $c */
function takesSpecificCallable(callable $c) : void {
$c("foo");
}
function takesCallable(callable $c) : void {
takesSpecificCallable($c);
}',
'error_message' => 'MixedArgumentTypeCoercion'
],
];
}
}

0 comments on commit 1a92e98

Please sign in to comment.