<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.3.4</td>
</tr>
</tbody>
</table>
<p dir="auto">When using multiple bundles (using the "old" structure from before the AppBundle / bundle-less usage) which use the <code class="notranslate">services.yml</code> convention to describe the services, and using anonymous services in multiple of these services files the dumped container doesn't work. This is because every anonymous service gets assigned an id based on a counter and the hash of the filename (<code class="notranslate">YamlFileLoader</code> line 691: <code class="notranslate">$id = sprintf('%d_%s', ++$this-&gt;anonymousServicesCount, hash('sha256', $file));</code>). But the <code class="notranslate">$file</code> is only the <code class="notranslate">services.yml</code> (as specified in the <code class="notranslate">-&gt;load</code> call), and the <code class="notranslate">anonymousServicesCount</code> is an instance variable and resetted in the <code class="notranslate">-&gt;load</code> call. This leads to duplicate ids for these anonymous services and will override the previous anonymous service.</p>
<p dir="auto">A simple test case for this is an Extension which uses two file loaders (which works the same as using multiple bundles each with its own extension using a single loader):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$loader = new YamlFileLoader(
  $container,
  new FileLocator(__DIR__.'/../Resources/config/foo')
);
$loader-&gt;load('services.yml');

$loader = new YamlFileLoader(
  $container,
  new FileLocator(__DIR__.'/../Resources/config/bar')
);
$loader-&gt;load('services.yml');"><pre class="notranslate"><code class="notranslate">$loader = new YamlFileLoader(
  $container,
  new FileLocator(__DIR__.'/../Resources/config/foo')
);
$loader-&gt;load('services.yml');

$loader = new YamlFileLoader(
  $container,
  new FileLocator(__DIR__.'/../Resources/config/bar')
);
$loader-&gt;load('services.yml');
</code></pre></div>
<p dir="auto">As services files the following can then be used:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="services:
  AppBundle\Hello:
    arguments:
      - !service {class: AppBundle\World}"><pre class="notranslate"><code class="notranslate">services:
  AppBundle\Hello:
    arguments:
      - !service {class: AppBundle\World}
</code></pre></div>
<p dir="auto">and</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="services:
  AppBundle\Foo:
    arguments:
      - !service {class: AppBundle\Bar }"><pre class="notranslate"><code class="notranslate">services:
  AppBundle\Foo:
    arguments:
      - !service {class: AppBundle\Bar }
</code></pre></div>
<p dir="auto">The dumped container will then contain just one anonymous service, being <code class="notranslate">1_21ea027d6c8c91cadbe51f665e92e08366c04a3d9e7e6eb94ba265237673a195</code> (in a proper setup there will be two more from the Config component), while there should be two (one to create the <code class="notranslate">AppBundle\World</code> instance and another to create the <code class="notranslate">AppBundle\Bar</code> instance).<br>
Further inspection then of course also reveals that both the <code class="notranslate">AppBundle\Hello</code> and <code class="notranslate">AppBundle\Foo</code> creation methods also reference the same service id, being that <code class="notranslate">1_21ea027d6c8c91cadbe51f665e92e08366c04a3d9e7e6eb94ba265237673a195</code> service.</p>
<p dir="auto">Given the following example:</p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="--parent.html.twig
&lt;div id=&quot;container&quot;&gt;
    {% block body %}
    {% endblock body %}
&lt;/div&gt;
{% block modals %}
{% endblock modals %}

--child.html.twig

{% extends &quot;parent.html.twig&quot; %}

{% block body %}
    {% block modals %}
        &lt;div id=&quot;childModal&quot;&gt;&lt;/div&gt;
    {% endblock modals %}
{% endblock body %}"><pre class="notranslate">--parent.html.twig
&lt;<span class="pl-ent">div</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>container<span class="pl-pds">"</span></span>&gt;
    {% <span class="pl-k">block</span> <span class="pl-smi">body</span> %}
    {% <span class="pl-k">endblock</span> <span class="pl-smi">body</span> %}
&lt;/<span class="pl-ent">div</span>&gt;
{% <span class="pl-k">block</span> <span class="pl-smi">modals</span> %}
{% <span class="pl-k">endblock</span> <span class="pl-smi">modals</span> %}

--child.html.twig

{% <span class="pl-k">extends</span> <span class="pl-s"><span class="pl-pds">"</span>parent.html.twig<span class="pl-pds">"</span></span> %}

{% <span class="pl-k">block</span> <span class="pl-smi">body</span> %}
    {% <span class="pl-k">block</span> <span class="pl-smi">modals</span> %}
        &lt;<span class="pl-ent">div</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>childModal<span class="pl-pds">"</span></span>&gt;&lt;/<span class="pl-ent">div</span>&gt;
    {% <span class="pl-k">endblock</span> <span class="pl-smi">modals</span> %}
{% <span class="pl-k">endblock</span> <span class="pl-smi">body</span> %}</pre></div>
<h1 dir="auto">childModal will appear twice in the rendering of child, once inside #container, and another one after it. Is this expected behaviour? It's a special case of nested blocks not reflected on <a href="http://twig.sensiolabs.org/doc/tags/extends.html" rel="nofollow">the manual</a></h1>