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

Config treatPhpDocTypesAsCertain is not honored for int ranges #7795

Closed
thg2k opened this issue Aug 15, 2022 · 5 comments
Closed

Config treatPhpDocTypesAsCertain is not honored for int ranges #7795

thg2k opened this issue Aug 15, 2022 · 5 comments

Comments

@thg2k
Copy link

thg2k commented Aug 15, 2022

Given following snippet:

/** @param int<0, 100> $b */
function foo(int $b): void {
	if ($b > 100) throw new \Exception("bad");
	print "ok";
}

https://phpstan.org/r/ace27b7e-79a6-40cc-8888-e27b49a46073

It correctly reports that the condition is always true when treatPhpDocTypesAsCertain is true, but if set to false then it should not report the error.

This is a legit safety check for the following use case: I want to specify the actual most strict type possible, to detect bad usage from calling library, but at the same time I have to put the check in place to avoid bad things to happen as PHP will only enforce the int type hinting.

@herndlm
Copy link
Contributor

herndlm commented Aug 15, 2022

Sounded so familiar, I think this is a duplicate of #7075 :)

@thg2k
Copy link
Author

thg2k commented Aug 15, 2022

Totally a duplicated, I actually searched but i stopped to the first hits, didn't go as far as april 2021.. and it's marked as easy fix :)

@thg2k thg2k closed this as completed Aug 15, 2022
@herndlm
Copy link
Contributor

herndlm commented Aug 15, 2022

maybe you could give it a try? :) looks like Ondrej added some infos already

@thg2k
Copy link
Author

thg2k commented Aug 16, 2022

maybe you could give it a try? :) looks like Ondrej added some infos already

@herndlm I did 😄 Can you test it? It should work as is but i won't know if it breaks something.. it's working for me.

phpstan/phpstan-src#1627

@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 Sep 17, 2022
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