Move extends validation into correctness visitor

This commit is contained in:
Fabien Potencier
2026-06-04 13:19:27 +02:00
parent d96eac3895
commit ffcae61b15
4 changed files with 29 additions and 13 deletions
+5 -1
View File
@@ -414,7 +414,7 @@ class Parser
return $this->parent || 0 < \count($this->traits);
}
public function setParent(?Node $parent): void
public function setParent(?Node $parent, bool $throwOnMultiple = true): void
{
if (null === $parent) {
trigger_deprecation('twig/twig', '3.12', 'Passing "null" to "%s()" is deprecated.', __METHOD__);
@@ -425,6 +425,10 @@ class Parser
}
if (null !== $this->parent) {
if (!$throwOnMultiple) {
return;
}
throw new SyntaxError('Multiple extends tags are forbidden.', $parent->getTemplateLine(), $parent->getSourceContext());
}