weixin_39581719 2020-11-22 04:05
浏览 0

Type gets replaced even when explicitly typed with @var

Describe the bug When an object (in my case a class field) is assigned, the documented type is replaced in that scope, even when the object has an explicit type already declared. This is a regression as this did not happen in prior versions.

To Reproduce


class A
{
    /**  int */
    public $b;
}

class B
{
    /**  A */
    private $a;

    private function replace() { return "test"; }

    public function __construct()
    {
        $this->a->b; // shows proper type info

        $this->a = $this->replace();

        // $this->a now shows as "string"
    }
}

Expected behavior Since $a has an explicit documentation, assignments should not replace the type. In a polymorphic/factory-based system, the base class will often be returned instead of the specific subclass being created, and this prevents immediate typing from working properly.

Platform and version Win10 x64, Intelliphense 2.3.13

该提问来源于开源项目:bmewburn/vscode-intelephense

  • 写回答

1条回答 默认 最新

  • weixin_39581719 2020-11-22 04:05
    关注

    Note that it works properly when inside of a function:

    
    function test()
    {
        /**  A */
        $a = "";
    
        $a->b; // shows proper type info, even though it was "overridden" by a string above, it respects the ``
    }
    
    评论

报告相同问题?