Skip to content

Updating nullable member of array field $this->array['field'] = expr does not use context information #7880

@thg2k

Description

@thg2k

Bug report

When you define a field as nullable array, updating one field in a context where it's not null results in an unwanted error:

Code snippet that reproduces the problem

class C {
  /** @var array{a: string, b: string}|null */
  private $a = null;

  public function foo(): void {
    if ($this->a !== null) {
      $this->a['b'] = "baz";
    }
  }
}

https://phpstan.org/r/d5591f7c-b4e1-40bc-adce-15e4d846a4f7

Expected output

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions