Skip to content

Commit

Permalink
Fix #1835 - move reference generation before argument analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 23, 2019
1 parent ec104be commit 4735955
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,6 @@ public static function analyze(
$stmt->inferredType->by_ref = $returns_by_ref;
}

if ($no_method_id) {
return self::checkMethodArgs(
null,
$stmt->args,
$found_generic_params,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
$statements_analyzer
);
}

if ($codebase->store_node_types
&& (!$context->collect_initializations
&& !$context->collect_mutations)
Expand All @@ -332,6 +321,17 @@ public static function analyze(
);
}

if ($no_method_id) {
return self::checkMethodArgs(
null,
$stmt->args,
$found_generic_params,
$context,
new CodeLocation($statements_analyzer->getSource(), $stmt),
$statements_analyzer
);
}

if (!$config->remember_property_assignments_after_call && !$context->collect_initializations) {
$context->removeAllObjectVars();
}
Expand Down Expand Up @@ -892,6 +892,14 @@ function (PhpParser\Node\Arg $arg) {
return true;
}

if ($codebase->store_node_types && $method_id) {
$codebase->analyzer->addNodeReference(
$statements_analyzer->getFilePath(),
$stmt->name,
$method_id . '()'
);
}

if ($context->collect_initializations && $context->calling_method_id) {
list($calling_method_class) = explode('::', $context->calling_method_id);
$codebase->file_reference_provider->addMethodReferenceToClassMember(
Expand Down Expand Up @@ -1084,14 +1092,6 @@ function (PhpParser\Node\Arg $arg) {
$args
);

if ($codebase->store_node_types && $method_id) {
$codebase->analyzer->addNodeReference(
$statements_analyzer->getFilePath(),
$stmt->name,
$method_id . '()'
);
}

if (isset($stmt->inferredType)) {
$return_type_candidate = $stmt->inferredType;
}
Expand Down
39 changes: 39 additions & 0 deletions tests/LanguageServer/SymbolLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,43 @@ public function bar() : void {

$this->assertSame('type: int', $symbol_at_position[0]);
}

/**
* @return void
*/
public function testGetSymbolPositionMissingArg()
{
$codebase = $this->project_analyzer->getCodebase();
$config = $codebase->config;
$config->throw_exception = false;

$this->addFile(
'somefile.php',
'<?php
namespace B;
class A {
/** @var int|null */
protected $a;
public function foo(int $i) : string {
return "hello";
}
public function bar() : void {
$this->foo();
}
}'
);

$codebase->file_provider->openFile('somefile.php');
$codebase->scanFiles();
$this->analyzeFile('somefile.php', new Context());

$symbol_at_position = $codebase->getReferenceAtPosition('somefile.php', new Position(12, 33));

$this->assertNotNull($symbol_at_position);

$this->assertSame('B\A::foo()', $symbol_at_position[0]);
}
}

0 comments on commit 4735955

Please sign in to comment.