Skip to content

Add @psalm-check-type and @psalm-check-type-exact.#7686

Merged
orklah merged 1 commit intovimeo:masterfrom
AndrolGenhald:feature/type-check-annotations
Feb 17, 2022
Merged

Add @psalm-check-type and @psalm-check-type-exact.#7686
orklah merged 1 commit intovimeo:masterfrom
AndrolGenhald:feature/type-check-annotations

Conversation

@AndrolGenhald
Copy link
Copy Markdown
Collaborator

@AndrolGenhald AndrolGenhald commented Feb 17, 2022

I initially added these as part of my TryAnalyzer rewrite to allow testing complicated finally types like this:

$foo = 1;
try {
        $foo = 2;
} catch (Exception $_) {
        $foo = 3;
} finally {
        $bar = $foo;
        /** @psalm-check-type-exact $bar = 1|2|3 */;
}
/** @psalm-check-type-exact $bar = 2|3 */;

Using the 'assertions' in tests doesn't work since the type is different inside the finally.

I decided to extract the new annotation from the rest of my changes and do a separate pull request since I think others may find it useful, and it should be much easier to review than the entire TryAnalyzer rewrite.

@AndrolGenhald AndrolGenhald added the release:feature The PR will be included in 'Features' section of the release notes label Feb 17, 2022
I initially added these as part of my TryAnalyzer rewrite to allow testing complicated `finally` types like this:
```
$foo = 1;
try {
        $foo = 2;
} catch (Exception $_) {
        $foo = 3;
} finally {
        $bar = $foo;
        /** @psalm-check-type-exact $bar = 1|2|3 */;
}
/** @psalm-check-type-exact $bar = 2|3 */;
```
Using the `'assertions'` in tests doesn't work since the type is different inside the `finally`.

I decided to extract the new annotation from the rest of my changes and do a separate pull request since I think others may find it useful, and it should be much easier to review than the entire TryAnalyzer rewrite.
@AndrolGenhald AndrolGenhald force-pushed the feature/type-check-annotations branch from d123cd7 to d09e420 Compare February 17, 2022 16:37
@orklah
Copy link
Copy Markdown
Collaborator

orklah commented Feb 17, 2022

That's so freaking great! I wanted something like that for ages!

@orklah orklah merged commit ec95244 into vimeo:master Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature The PR will be included in 'Features' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants