Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't accept unresolved literal string as valid callable-strings #6979

Merged
merged 2 commits into from Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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