Skip to content
Permalink
Browse files

Fix #1835 - move reference generation before argument analysis

  • Loading branch information...
muglug committed Jun 23, 2019
1 parent ec104be commit 473595582970a29a3770e2fed18b835a003ec685
@@ -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)
@@ -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();
}
@@ -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(
@@ -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;
}
@@ -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.
You can’t perform that action at this time.