Type %s is redundant with type %s

Description

In a DNF (Disjunctive Normal Form) type, two intersection groups can look textually different while describing the exact same combination of types once names are resolved. Here, B is only a local alias for A (introduced by use A as B;), so X&A and X&B are, in fact, the very same intersection written twice.

PHP resolves use aliases at compile time, notices that the second group adds nothing over the first, and reports it as redundant.

Example

<?php

interface X {}

use A as B;

function foo(): (X&A)|(X&B) {}

?>

Literal Examples

  • Type X&A is redundant with type X&A

Solutions

  • Remove the duplicated intersection group.

  • Use the class’s real name consistently, instead of mixing the name and its alias.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.