Pseudo-class :last-child not working

Pseudo-classe li:last-child not working if not in direct child.

:last-child NOT working

<ul>
    <a href=""><li>first child</li></a>
    <a href=""><li>middle child</li></a>
    <a href=""><li>last child</li></a>
</ul>

:last-child working

<ul>
    <li><a href="">first child</a></li>
    <li><a href="">middle child</a></li>
    <li><a href="">last child</a></li>
</ul>