Better substitution of specializations of the form expr = const

Fixes #364