Skip to content

False DocblockTypeContradiction on === between overlapping types (callable/string, callable/array, numeric/string, iterable/object) #13957

Closed

Description

@orklah

=== between two types that overlap but are not contained in each other reports a DocblockTypeContradiction, as if the types were disjoint. All four comparisons below can be true at runtime (the comment gives a value that is both types).

<?php

/**
 * @param callable $c
 * @param string $s
 * @param array $a
 * @param numeric $n
 * @param iterable<int> $it
 * @param object $o
 */
function compare($c, $s, $a, $n, $it, $o): void
{
    if ($c === $s) {} // 'strlen'
    if ($c === $a) {} // [new ArrayObject(), 'count']
    if ($n === $s) {} // '1'
    if ($it === $o) {} // new ArrayIterator([1])
}

https://psalm.dev/r/3ed334d03a

Output:

ERROR: DocblockTypeContradiction - 13:9 - string does not contain callable[impure]
ERROR: DocblockTypeContradiction - 14:9 - array<array-key, mixed> does not contain callable[impure]
ERROR: DocblockTypeContradiction - 15:9 - string does not contain numeric
ERROR: DocblockTypeContradiction - 16:9 - object does not contain iterable<mixed, int>

Expected: no issue. The intersections are callable-string, callable-array, numeric-string and Traversable<mixed, int>.

Type::intersectUnionTypes() returns null (no overlap) for these pairs: intersectAtomicTypes() has no rule for them and neither side is contained in the other. The === assertion (AssertionFinder) then reports the contradiction. The same function is used in other places (reconciliation, templates, method return types), so they get the same wrong "no overlap" result.

Activity

  1. psalm-github-bot commented on Nov 16, 2026

    @psalm-github-bot

    I found these snippets:

    https://psalm.dev/r/3ed334d03a
    <?php
    
    /**
     * @param callable $c
     * @param string $s
     * @param array $a
     * @param numeric $n
     * @param iterable<int> $it
     * @param object $o
     */
    function compare($c, $s, $a, $n, $it, $o): void
    {
        if ($c === $s) {} // 'strlen'
        if ($c === $a) {} // [new ArrayObject(), 'count']
        if ($n === $s) {} // '1'
        if ($it === $o) {} // new ArrayIterator([1])
    }
    Psalm output (using commit 91eb0c4):
    
    ERROR: DocblockTypeContradiction - 13:9 - string does not contain callable[impure]
    
    ERROR: DocblockTypeContradiction - 14:9 - array<array-key, mixed> does not contain callable[impure]
    
    ERROR: DocblockTypeContradiction - 15:9 - string does not contain numeric
    
    ERROR: DocblockTypeContradiction - 16:9 - object does not contain iterable<mixed, int>
    
  2. added a commit that references this issue on Nov 17, 2026
    38a66c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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