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

Use classlike_storage_provider only if it has the required data #8376

Merged
merged 2 commits into from Aug 8, 2022

Conversation

Daeroni
Copy link
Contributor

@Daeroni Daeroni commented Aug 5, 2022

Fixes #8373

@AndrolGenhald
Copy link
Collaborator

Could you add a test to ensure this continues working in the future? Probably add something in AssertAnnotationTest.

@AndrolGenhald AndrolGenhald added the release:fix The PR will be included in 'Fixes' section of the release notes label Aug 6, 2022
@Daeroni
Copy link
Contributor Author

Daeroni commented Aug 6, 2022

It seems the bug requires the @psalm-assert annotation to be in a file that is not being analyzed (eg. library code from vendor-dir) but is included by the code being analyzed.

I tried to write a separate test method that adds to files to the scanner with addFilesToShallowScan and then just call addFilesToAnalyze to the file that is being tested (somewhat copied from the IncludeTest), but was unable to trigger the error.

I also tried to make a test project using the same package and similar code that our project has that triggers this error, but I couldn't reproduce it.

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Aug 8, 2022

How about this? Maybe add that to ClassTemplateTest.php?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/cce84834fa
<?php

/**
 * @psalm-suppress UndefinedDocblockClass
 *
 * @param DoesNotExist<int> $baz
 */
function foobar(DoesNotExist $baz): void {}

/**
 * @psalm-suppress UndefinedDocblockClass, UndefinedClass
 * @var DoesNotExist
 */
$baz = new DoesNotExist();
foobar($baz);
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for doesnotexist

Undefined classes in function dockblocks should not crash psalm.
Test provided by @AndrolGenhald
@Daeroni
Copy link
Contributor Author

Daeroni commented Aug 8, 2022

@AndrolGenhald Thanks, that seems to work.

@AndrolGenhald AndrolGenhald merged commit aae5395 into vimeo:4.x Aug 8, 2022
@AndrolGenhald
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncatched exception if psalm-assert references unknown class/interface
2 participants