This was never a problem.
If the sub-menu is nested within the main menu, you are still hovering the parent element, while you are hovering the sub-menu item nested within. So a simple :hover selector for both elements will do.
But the problem I always saw (in the past now) with this kind of drop-down menu system, was keyboard accessibilty.
For that I generally pair my :hover selectors with :focus selectors, so keybord users see the same highlighting as mouse users, as they tab through the menu.
But with drop-down sub-menus, this was an issue, as the :hover was used to make the sub-menu appear (drop down), as could :focus. But when a user tabs focus onto a sub-menu item, the parent loses focus, and the sub-menu becomes invisible again, and the user is tabbing blind.
Admittedly, this is not what the OP was asking specifically about, but asking a simple question, and then replies saying it can’t be done, tricked me into thinking I was answering a more difficult question.
But still it is quite relevant to the job in hand, and worthy of consideration by the OP and other readers.