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

Add a parent interface does not properly invalidate the cache #5056

Closed
stof opened this issue May 22, 2021 · 6 comments
Closed

Add a parent interface does not properly invalidate the cache #5056

stof opened this issue May 22, 2021 · 6 comments

Comments

@stof
Copy link
Contributor

stof commented May 22, 2021

Bug report

When adding a extends \Throwable on an interface that is already used in a @throws tag, phpstan does not properly pick the change to remove the error on the @throws tag unless I manually remove /tmp/phpstan to clear the cache.

Code snippet that reproduces the problem

<?php

namespace ScssPhp\ScssPhp\Exception;

interface SassException
{
}
<?php

namespace ScssPhp\ScssPhp;

use ScssPhp\ScssPhp\Exception\SassException;

class Compiler
{
	/**
	 * @throws SassException
	 */
	public function compileString(string $source): string
	{
		return $source;
	}
}
  1. run phpstan at max level to analyze it
  2. generate the baseline to ignore the error PHPDoc tag @throws with type ScssPhp\ScssPhp\Exception\SassException is not subtype of Throwable
  3. edit SassException.php to add extends \Throwable on the interface
  4. run phpstan again

Expected output

phpstan should not report that the ignored error is useless (and if we omit the baseline, it should not report the error).
However, until I cleared the cache manually, it kept reporting the error about @throws using a non-Throwable type.

Did PHPStan help you today? Did it make you happy in any way?

Thanks for the project. Static analysis is definitely helpful.

@mergeable
Copy link

mergeable bot commented May 22, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@stof
Copy link
Contributor Author

stof commented May 22, 2021

I could not provide a reproduction on phpstan.org, as this is a cache invalidation issue.

@ondrejmirtes
Copy link
Member

Can you please verify that this fix (phpstan/phpstan-src@30ec3a0) works by running: composer require --dev phpstan/phpstan:dev-master --prefer-dist and re-running your steps to reproduce? Thanks.

@stof
Copy link
Contributor Author

stof commented May 24, 2021

@ondrejmirtes this does not solve it when reproducing it on the actual scssphp repository where I faced it.

How I tried it (in my scssphp clone):

  1. git checkout 214e63048bd963ae3bbf8d1f45330bc8add5faf0
  2. rm -rf /tmp/phpstan
  3. make phpstan (which just runs phpstan on the project)
  4. git checkout 33c2ccd90a829618444bbbae798d114819fc6154 (that's the commit adding the extends Throwable` on the interface)
  5. make phpstan

And then, I did the same again with our vendor-bin/phpstan/composer.json file patched to install dev-master instead of the released version. And it still reported the issue about SassException not being a subtype.

modified file
{
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "require": {
        "phpstan/phpstan": "dev-master"
    }
}

@ondrejmirtes
Copy link
Member

Fixed and tested, thank you! phpstan/phpstan-src@d53a9a1

@github-actions
Copy link

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 Jun 26, 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