Fix issue with shape functions.

The problem is that assertions would sometimes be optimised out.  The
solution is a bit of a hack, though.