Page MenuHomePhabricator

Bogus PhanCoalescingNeverNull error
Closed, ResolvedPublic

Description

https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/b23c1f0e9eed1f1eddb2ba5543228683ffbc5bcb/includes/session/SessionBackend.php#828
gives https://integration.wikimedia.org/ci/job/mediawiki-core-php74-phan/26288/console :

15:33:28 includes/session/SessionBackend.php:828 PhanCoalescingNeverNull Using non-null $persistenceChangeReason of type 'token'|non-empty-mixed as the left hand side of a null coalescing (??) operation. The right hand side may be unnecessary.

which just seems very bogus, it takes its value from an object property which starts as null, is periodically reset to null, and plenty of code paths leading to the logging code never touch it. No idea how Phan could get it wrong.

I imagine this should be upstreamed, I just don't have the energy to create a standalone testcase right now.

Event Timeline

Linking your change: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1143959

It is using type declaration on the class property, often this makes phan more strict about types.

There is also a check that this is not-null in the same function. Not reachabe for every code path, so this could be a bug.

			if ( !$this->persistenceChangeReason ) {
				$this->persistenceChangeReason = 'token';
			}

Maybe phan is happy with a null-coalesce assignment instead

			$this->persistenceChangeReason ??= 'token';

The revision that generated this error didn't use a type declaration (although then I added one and Phan didn't complain about the suppression being unnecessary, so I suppose it's still confused about whether persistenceChangeReason can be null). The token stuff seems too late to be relevant, by that point Phan decided the property has non-empty-mixed type. (It's actually not mixed, all values are string or null; and this is a private property, so that shouldn' be hard to analyze.)

Daimona subscribed.

Upstreamed: https://github.com/phan/phan/issues/4916. Definitely a bug, likely related to the special-cased tracking of properties of $this in local context.

This was released in phan 5.4.6,, we are now on 5.5.2 I think ? Shall we close this ?

Daimona claimed this task.

Yup, makes sense!