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

Interface type hint change for callable types is not always respected #4054

Closed
ramonacat opened this issue Nov 4, 2020 · 3 comments
Closed

Comments

@ramonacat
Copy link

Bug report

When a class depends on an interface, that takes a callable argument, after changing the typehint in docblock on the interface, the class is still analysed as-if the previous typehint was present

Code snippet that reproduces the problem

  1. Create TestInterface.php:
<?php

interface TestInterface
{
	/**
	 * @param callable(string): void $do
	 */
	public function test(callable $do): void;
}

and Executor.php:

<?php
final class Executor implements TestInterface
{
	public function test($do): void
	{
		$do('z');
	}
}
  1. Run ./vendor/bin/phpstan analyse --level 8 TestInterface.php Executor.php (there will be no errors - as expected)
  2. Change the typehint on TestInterface (the closure got a second argument):
<?php

interface TestInterface
{
	/**
	 * @param callable(string, string): void $do
	 */
	public function test(callable $do): void;
}
  1. Run ./vendor/bin/phpstan analyse --level 8 TestInterface.php Executor.php (there will be no errors, which is now incorrect). If any change to Executor.php is made, the errors appear as expected.

Expected output

 2/2 [============================] 100%

 ------ -------------------------------------------------------------------------------
  Line   Executor.php
 ------ -------------------------------------------------------------------------------
  6      Callable callable(string, string): void invoked with 1 parameter, 2 required.
 ------ -------------------------------------------------------------------------------
@mergeable
Copy link

mergeable bot commented Nov 4, 2020

This bug report is missing a link to reproduction on phpstan.org.
It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Fixed, thank you! phpstan/phpstan-src@e36e1cd

@github-actions
Copy link

github-actions bot commented May 9, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants