Fix regression with SUM(), and test case to catch it.

Change-Id: I76061ce5d975ac565d49b89f8365e355aa0ad009