Seems to be a compiler bug. This is really strange. I just rephrased the whole thing and it appears to work.