psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Errors are not shown with baseline file and output-format=compact

Open andrey-tech opened this issue 1 year ago • 3 comments

Hi!

I have a problem with Psalm v5.23.1 and PHP 8.1: new errors are NOT SHOWN in the console if I use baseline file and output-format=compact (other output formats - OK). Please check and fix!

Description

  1. Example with option --output-format=compact — new errors are NOT SHOWN in the console, but Psalm exit code is 2:
vendor/bin/psalm --config=psalm.xml.dist --output-format=compact --use-baseline=psalm-baseline.xml src/Kernel.php

Target PHP version: 8.1 (set by config file) Enabled extensions: dom, mongodb, pdo, simplexml, soap (unsupported extensions: fileinfo, zend-opcache).          
Scanning files...
Analyzing files...

░
FILE: src/Kernel.php
  1. Example without option --output-format all new errors are SHOWN in the console and Psalm exit code is 2:
vendor/bin/psalm --config=psalm.xml.dist --use-baseline=psalm-baseline.xml src/Kernel.php         

Target PHP version: 8.1 (set by config file) Enabled extensions: dom, mongodb, pdo, simplexml, soap (unsupported extensions: fileinfo, zend-opcache).
Scanning files...
Analyzing files...

░

To whom it may concern: Psalm cannot detect unused classes, methods and properties
when analyzing individual files and folders. Run on the full project to enable
complete unused code detection.

ERROR: InvalidReturnType - src/Kernel.php:43:36 - The declared return type 'int' for App\Kernel::getCacheDir is incorrect, got 'non-falsy-string' (see https://psalm.dev/011)
    public function getCacheDir(): int


ERROR: InvalidReturnStatement - src/Kernel.php:45:16 - The inferred type 'non-falsy-string' does not match the declared return type 'int' for App\Kernel::getCacheDir (see https://psalm.dev/128)
        return '/tmp/cache/' . $this->environment;

------------------------------
2 errors found
------------------------------
10 other issues found.
You can display them with --show-info=true
------------------------------
Psalm can automatically fix 1 of these issues.
Run Psalm again with
--alter --issues=InvalidReturnType --dry-run
to see what it can fix.
------------------------------

Checks took 2.58 seconds and used 227.321MB of memory
Psalm was able to infer types for 90.6667% of the codebase

andrey-tech avatar Apr 02 '24 12:04 andrey-tech

Hey @andrey-tech, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

psalm-github-bot[bot] avatar Apr 02 '24 12:04 psalm-github-bot[bot]

Hey @psalm-github-bot, I can't reproduce the issue on psalm.dev, because this is a console options issue.

andrey-tech avatar Apr 02 '24 13:04 andrey-tech