Related to #21982, which however only fixes one particular case: there are more. Will soon push a branch with more substantial changes - which however is still not ready (breaks some tests).