Skip to content

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

@ramonacat

Description

@ramonacat

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.
 ------ -------------------------------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions