refactor(scope): remove special-case handling of $this
parent
7dd0f10564
commit
a8829a9b44
|
@ -201,9 +201,6 @@ class CompletionProvider
|
|||
$prefixLen = strlen($namePrefix);
|
||||
$scope = getScopeAtNode($this->definitionResolver, $node);
|
||||
$variables = $scope->variables;
|
||||
if ($scope->thisVariable !== null) {
|
||||
$variables['this'] = $scope->thisVariable;
|
||||
}
|
||||
foreach ($variables as $name => $var) {
|
||||
if (substr($name, 0, $prefixLen) !== $namePrefix) {
|
||||
continue;
|
||||
|
|
|
@ -563,9 +563,6 @@ class DefinitionResolver
|
|||
// $myVariable -> type of corresponding assignment expression
|
||||
if ($expr instanceof Node\Expression\Variable || $expr instanceof Node\UseVariableName) {
|
||||
$name = $expr->getName();
|
||||
if ($name === 'this') {
|
||||
return $scope->thisVariable === null ? new Types\Mixed_ : $scope->thisVariable->type;
|
||||
}
|
||||
return isset($scope->variables[$name])
|
||||
? $scope->variables[$name]->type
|
||||
: new Types\Mixed_;
|
||||
|
|
|
@ -9,13 +9,6 @@ use Microsoft\PhpParser\Node\QualifiedName;
|
|||
*/
|
||||
class Scope
|
||||
{
|
||||
/**
|
||||
* @var Variable|null $this
|
||||
*
|
||||
* Note that this will be set when a class is entered. It is unset again when entering a static function.
|
||||
*/
|
||||
public $thisVariable;
|
||||
|
||||
/**
|
||||
* @var Variable|null $this, except also set in static contexts.
|
||||
*/
|
||||
|
|
|
@ -102,8 +102,8 @@ class TreeTraverser
|
|||
$childScope->currentClassLikeVariable = $scope->currentClassLikeVariable;
|
||||
$childScope->resolvedNameCache = $scope->resolvedNameCache;
|
||||
$isStatic = $node instanceof Node\MethodDeclaration ? $node->isStatic() : !empty($node->staticModifier);
|
||||
if (!$isStatic) {
|
||||
$childScope->thisVariable = $scope->thisVariable;
|
||||
if (!$isStatic && isset($scope->variables['this'])) {
|
||||
$childScope->variables['this'] = $scope->variables['this'];
|
||||
}
|
||||
|
||||
if ($node->parameters !== null) {
|
||||
|
@ -138,11 +138,12 @@ class TreeTraverser
|
|||
) {
|
||||
$childScope = new Scope;
|
||||
$childScope->resolvedNameCache = $scope->resolvedNameCache;
|
||||
$childScope->thisVariable = new Variable(
|
||||
$thisVar = new Variable(
|
||||
new Types\Object_(new Fqsen('\\' . (string)$node->getNamespacedName())),
|
||||
$node
|
||||
);
|
||||
$childScope->currentClassLikeVariable = $childScope->thisVariable;
|
||||
$childScope->variables['this'] = $thisVar;
|
||||
$childScope->currentClassLikeVariable = $thisVar;
|
||||
return $childScope;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ class TreeAnalyzer
|
|||
}
|
||||
|
||||
// Check for invalid usage of $this.
|
||||
if ($scope->thisVariable === null &&
|
||||
$node instanceof Node\Expression\Variable &&
|
||||
if ($node instanceof Node\Expression\Variable &&
|
||||
!isset($scope->variables['this']) &&
|
||||
$node->getName() === 'this'
|
||||
) {
|
||||
$this->diagnostics[] = new Diagnostic(
|
||||
|
|
Loading…
Reference in New Issue