Skip to content
Permalink
Browse files

Warn about more generic callables

  • Loading branch information
muglug committed Dec 14, 2019
1 parent ce2e5b2 commit 1a92e98dd3e66af9ab638e65925705b6616a18be
Showing with 27 additions and 0 deletions.
  1. +15 −0 src/Psalm/Internal/Analyzer/TypeAnalyzer.php
  2. +12 −0 tests/CallableTest.php
@@ -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
) {
@@ -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.
You can’t perform that action at this time.