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