Fix inheritance logic to be able to use instanceof ContextVariable instead of NameExpression

This commit is contained in:
Fabien Potencier
2025-01-23 18:39:15 +01:00
parent 72c91f6260
commit b6d9dd62ee
15 changed files with 33 additions and 22 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\AssignTemplateVariable;
use Twig\Node\Expression\Variable\ContextVariable;
/**
* Represents an import node.
@@ -44,7 +45,7 @@ class ImportNode extends Node
{
$compiler->subcompile($this->getNode('var'));
if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) {
if ($this->getNode('expr') instanceof ContextVariable && '_self' === $this->getNode('expr')->getAttribute('name')) {
$compiler->raw('$this');
} else {
$compiler