1
0
Fork 0

Try to lookup base class member while resolveExpressionNodeToType

pull/408/head
Fuyao Zhao 2017-06-15 05:28:49 +08:00
parent 8d1732ed02
commit 51d6128cde
1 changed files with 24 additions and 6 deletions

View File

@ -656,13 +656,31 @@ class DefinitionResolver
} else { } else {
$classFqn = substr((string)$t->getFqsen(), 1); $classFqn = substr((string)$t->getFqsen(), 1);
} }
$fqn = $classFqn . '->' . $expr->memberName->getText($expr->getFileContents());
if ($expr->parent instanceof Node\Expression\CallExpression) { $memberSuffix = '->' . $expr->memberName->getText($expr->getFileContents());
$fqn .= '()'; if ($expr instanceof Node\Expression\CallExpression) {
$memberSuffix .= '()';
} }
$def = $this->index->getDefinition($fqn);
if ($def !== null) { // Find the right class that implements the member
return $def->type; $implementorFqns = [$classFqn];
while ($implementorFqn = array_shift($implementorFqns)) {
// If the member FQN exists, return it
if ($def = $this->index->getDefinition($implementorFqn . $memberSuffix)) {
return $def->type;
}
// Get Definition of implementor class
$implementorDef = $this->index->getDefinition($implementorFqn);
// If it doesn't exist, return the initial guess
if ($implementorDef === null) {
break;
}
// Repeat for parent class
if ($implementorDef->extends) {
foreach ($implementorDef->extends as $extends) {
$implementorFqns[] = $extends;
}
}
} }
} }
} }