Skip to content

Config treatPhpDocTypesAsCertain is not honored for int ranges #7795

@thg2k

Description

@thg2k

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions