Page MenuHomePhabricator

Phan complains about a numeric input
Closed, DuplicatePublic

Description

From https://integration.wikimedia.org/ci/job/mwext-php72-phan-docker/52494/console which is based on patch set 1 of https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/CheckUser/+/596495/ we see:

<error line="109" severity="info" message="Argument 2 ($value) is ?0|?non-zero-int but \ApiQueryCheckUser::addWhereFld() takes int|int[]|string|string[] defined at ../../includes/api/ApiQueryBase.php:267 (expected type to be non-nullable)" source="PhanTypeMismatchArgumentNullable"/>

The value of argument 2, i.e. $user_id comes from User::getIdFromName() which can only return null or an int. I even changed line 104 to explicitly check for nulls, but phan is still not a big fan of my patch.

Event Timeline

Daimona subscribed.

Phan complains because $user_id can potentially be null, but addWhereFld doesn't take null, so phan would theoretically be right here. However, as you noticed, it cannot infer from the if above that the null case is discarded. This is because phan doesn't know that calling dieWithError() will throw an exception, and this, in turn, is a constant source of pain, see T240141. I suggest suppressing the issue inline, and mentioning that task in the suppression message so it can be easily identified. In short: @phan-suppress-next-line PhanTypeMismatchArgumentNullable T240141.