Improve error message for static assert

by running optimize first.