Skip to content

Commit

Permalink
Merge pull request #6979 from orklah/6975
Browse files Browse the repository at this point in the history
don't accept unresolved literal string as valid callable-strings
  • Loading branch information
orklah committed Nov 23, 2021
2 parents 60f0fd1 + 7c6b86c commit fdf3a8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php
Expand Up @@ -582,6 +582,11 @@ public static function isContainedBy(
}
}

if (!$input_callable) {
//we could not find a callable for the input type, so the input is not contained in the container
return false;
}

return true;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -1219,6 +1219,18 @@ function foo(string $c) : void {
}',
'error_message' => 'InvalidScalarArgument',
],
'inexistantCallableinCallableString' => [
'<?php
/**
* @param callable-string $c
*/
function c(string $c): void {
$c();
}
c("hii");',
'error_message' => 'InvalidArgument',
],
];
}
}
1 change: 1 addition & 0 deletions tests/TypeParseTest.php
Expand Up @@ -973,6 +973,7 @@ function someFunction(string $param, array $param2, ?int $param3 = null) : strin
}
}

/** @psalm-suppress InvalidArgument Psalm couldn't detect the function exists */
$reflectionFunc = new \ReflectionFunction('Psalm\Tests\someFunction');
$reflectionParams = $reflectionFunc->getParameters();

Expand Down

0 comments on commit fdf3a8d

Please sign in to comment.