This simple patch resolves #46756 (which was specifically about the case of casts, but it would be poor form indeed to fix a reported issue without at least a cursory attempt at answering the immortal question, "How does this bug generalize?").