Skip to content

NodeTypeResolver failed to resolve correct variable type when it's surrounded by parenthesis #90

Description

@halftan

When getting candidates in this situation:

<?php
$parser = new PhpParser\ParserFactory-><TAB>

$context->getData() in ObjectCompleter returns:

array(4) {
  [0]=>
  object(Padawan\Domain\Project\FQCN)#97 (3) {
    ["_isArray":"Padawan\Domain\Project\FQCN":private]=>
    bool(false)
    ["_isScalar":"Padawan\Domain\Project\FQCN":private]=>
    bool(false)
    ["parts":"Padawan\Domain\Project\FQN":private]=>
    array(2) {
      [0]=>
      string(9) "PhpParser"
      [1]=>
      string(13) "ParserFactory"
    }
  }
  [1]=>
  bool(false)
  [2]=>
  array(0) {
  }
  [3]=>
  object(PhpParser\Node\Expr\Assign)#80 (3) {
    ["var"]=>
    object(PhpParser\Node\Expr\Variable)#184149 (2) {
      ["name"]=>
      string(6) "parser"
      ["attributes":protected]=>
      array(2) {
        ["startLine"]=>
        int(1)
        ["endLine"]=>
        int(1)
      }
    }
    ["expr"]=>
    object(PhpParser\Node\Expr\New_)#81 (3) {
      ["class"]=>
      object(PhpParser\Node\Name)#184212 (2) {
        ["parts"]=>
        array(2) {
          [0]=>
          string(9) "PhpParser"
          [1]=>
          string(13) "ParserFactory"
        }
        ["attributes":protected]=>
        array(2) {
          ["startLine"]=>
          int(1)
          ["endLine"]=>
          int(1)
        }
      }
      ["args"]=>
      array(0) {
      }
      ["attributes":protected]=>
      array(2) {
        ["startLine"]=>
        int(1)
        ["endLine"]=>
        int(1)
      }
    }
    ["attributes":protected]=>
    array(2) {
      ["startLine"]=>
      int(1)
      ["endLine"]=>
      int(1)
    }
  }
}

which is desired.

But when in this situation:

<?php
$parser = (new PhpParser\ParserFactory)-><TAB>

it returns:

array(4) {
  [0]=>
  NULL
  [1]=>
  bool(false)
  [2]=>
  array(0) {
  }
  [3]=>
  object(PhpParser\Node\Expr\Variable)#184149 (2) {
    ["name"]=>
    string(6) "parser"
    ["attributes":protected]=>
    array(2) {
      ["startLine"]=>
      int(1)
      ["endLine"]=>
      int(1)
    }
  }
}

which is not desired and need to be fixed.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions