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

Redundant cast to Int preserve type #5773

Merged
merged 2 commits into from May 15, 2021
Merged

Redundant cast to Int preserve type #5773

merged 2 commits into from May 15, 2021

Conversation

orklah
Copy link
Collaborator

@orklah orklah commented May 15, 2021

This PR conserve the type of an int expression that passes through an int cast. Before this PR, it was widened to TInt: https://psalm.dev/r/7f34cf6a8d

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7f34cf6a8d
<?php

/**
 * @param positive-int $i
 * @return positive-int
 */
function takesAnInt(int $i) {
    return (int)$i;
}
Psalm output (using commit 1195335):

ERROR: RedundantCast - 8:12 - Redundant cast to int

INFO: LessSpecificReturnStatement - 8:12 - The type 'int' is more general than the declared return type 'positive-int' for takesAnInt

INFO: MoreSpecificReturnType - 5:12 - The declared return type 'positive-int' for takesAnInt is more specific than the inferred return type 'int'

@muglug muglug merged commit 6501ca7 into vimeo:master May 15, 2021
@muglug
Copy link
Collaborator

muglug commented May 15, 2021

Thanks!

@orklah orklah deleted the IntCast branch September 14, 2021 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants