<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.2.x</p>
<p dir="auto"><strong>Description</strong><br>
When using the Validator component with a Comparison constraint, the AbstractComparisonValidator only looks at the ExecutionContext object to compare values, not the root, see these lines: <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php#L51-L53">https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php#L51-L53</a></p>
<p dir="auto"><strong>How to reproduce</strong><br>
Validate an array of data with a comparison constraint:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$validator = Validation::createValidator();
$constraint = new Assert\Collection([
    'password' =&gt; [
       new Constraints\NotBlank(),
    ],
    'repeat-password' =&gt; [
       new Constraints\IdenticalTo(['propertyPath' =&gt; 'password'])
    ],
]);

$violations = $validator-&gt;validate(['password' =&gt; 'foo', 'repeat-password' =&gt; 'bar', $constraint);"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>validator</span> = <span class="pl-v">Validation</span>::<span class="pl-en">createValidator</span>();
<span class="pl-s1"><span class="pl-c1">$</span>constraint</span> = <span class="pl-k">new</span> <span class="pl-v">Assert</span>\<span class="pl-v">Collection</span>([
    <span class="pl-s">'password'</span> =&gt; [
       <span class="pl-k">new</span> <span class="pl-v">Constraints</span>\<span class="pl-v">NotBlank</span>(),
    ],
    <span class="pl-s">'repeat-password'</span> =&gt; [
       <span class="pl-k">new</span> <span class="pl-v">Constraints</span>\<span class="pl-v">IdenticalTo</span>([<span class="pl-s">'propertyPath'</span> =&gt; <span class="pl-s">'password'</span>])
    ],
]);

<span class="pl-s1"><span class="pl-c1">$</span>violations</span> = <span class="pl-s1"><span class="pl-c1">$</span>validator</span>-&gt;<span class="pl-en">validate</span>([<span class="pl-s">'password'</span> =&gt; <span class="pl-s">'foo'</span>, <span class="pl-s">'repeat-password'</span> =&gt; <span class="pl-s">'bar'</span>, <span class="pl-s1"><span class="pl-c1">$</span>constraint</span>);</pre></div>
<p dir="auto"><strong>Possible Solution</strong><br>
If the ExecutionContext object is null, use the root of the ExecutionContext to get the compared value.</p>
<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.1.x</p>
<p dir="auto"><strong>Description</strong><br>
When I attach to an object of mine through Yaml or annotation one of the <code class="notranslate">EqualsTo/NotEqualsTo/IdenticalTo/NotIdenticalTo</code> constraints then <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php#L56">this line</a> returns the object that the constraint is attached to.</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="App\Form\Transfer:
    properties:
        from:
            - NotIdenticalTo:
                propertyPath: 'to'"><pre class="notranslate"><span class="pl-ent">App\Form\Transfer</span>:
    <span class="pl-ent">properties</span>:
        <span class="pl-ent">from</span>:
            - <span class="pl-ent">NotIdenticalTo</span>:
                <span class="pl-ent">propertyPath</span>: <span class="pl-s"><span class="pl-pds">'</span>to<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">So the line above will return the object <code class="notranslate">App\Form\Transfer</code></p>
<p dir="auto">If I add the constraint on a form type like this:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="        $builder
            -&gt;add('from', ChoiceType::class, [
                'constraints' =&gt; [
                    new NotIdenticalTo(['propertyPath' =&gt; 'to']),
                ],
            ])"><pre class="notranslate">        <span class="pl-s1"><span class="pl-c1">$</span>builder</span>
            -&gt;<span class="pl-en">add</span>(<span class="pl-s">'from'</span>, <span class="pl-v">ChoiceType</span>::class, [
                <span class="pl-s">'constraints'</span> =&gt; [
                    <span class="pl-k">new</span> <span class="pl-v">NotIdenticalTo</span>([<span class="pl-s">'propertyPath'</span> =&gt; <span class="pl-s">'to'</span>]),
                ],
            ])</pre></div>
<p dir="auto">The line above will bring back a form object.</p>
<p dir="auto">This causes the constraint to throw an exception because it reaches on <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php#L58">this line</a> and in the Form object the path of the property it does not exist.</p>
<p dir="auto"><strong>How to reproduce</strong></p>
<p dir="auto">Build a form in the way described above and submit it.</p>