Skip to content

Nullsafe fetch on a non-null property receiver is typed nullable since 7.7.0 #13936

Closed

Description

@alies-dev

https://psalm.dev/r/baae6a6cd3

What Psalm reports / does
Trace: $_r is bool|null. $h->item is a non-null Item (Psalm itself reports RedundantCondition: Type Item for $h->item is never null), so ?-> never short-circuits and the null branch is dead. Psalm 7.6.0 gives bool.

Since 7.7.0, NullsafeAnalyzer takes the receiver type of a property-fetch receiver from $context->vars_in_scope; a property fetch that was not read before is absent there, so $var_type is null and the non-null fast path is skipped.

What you expected
$_r is bool, as on 7.6.0.

Psalm version, PHP version
psalm.dev 7.x-dev, PHP default; also 7.7.0 locally (7.6.0 is correct)

Activity

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

    @psalm-github-bot

    I found these snippets:

    https://psalm.dev/r/baae6a6cd3
    <?php
    
    final class Item { public bool $flag = true; }
    
    final class Holder
    {
        public function __construct(public Item $item) {}
    }
    
    function f(Holder $h): void
    {
        $_r = $h->item?->flag;
        /** @psalm-trace $_r */
    }
    Psalm output (using commit 83b3d2a):
    
    ERROR: TypeDoesNotContainNull - 12:11 - Item does not contain null
    
    ERROR: RedundantCondition - 12:11 - Type Item for $h->item is never null
    
    INFO: Trace - 13:0 - $_r: bool|null
    
  2. added a commit that references this issue on Nov 16, 2026
  3. self-assigned this
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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