Skip to content

@var annotation is ignored for class constants #942

@weirdan

Description

@weirdan

https://getpsalm.org/r/03a2f11ca3

<?php
  /** @param void ...$_p*/
  function type(...$_p): void {}

  class C {
    /** @var int[] */
    const N = [];
  }

  type(C::N);

Expected: should complain about array<mixed,int> provided
Actual: complains about array<empty,empty> provided

There's at least one usage of @var on constants in Psalm's tests:

/**
* @var string[]
*/
protected const VALUES = [];

Additionally, psalm seems to ignore @var and const initialization contradiction:

<?php
class C {
  /** @var int */
  public const N = "aaaa"; // should produce issues, but doesn't
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions