Fix #1021: IR-check assignment to val fields

Assignment to immutable val fields is only allowed in constructors.

Note that scalac generates code in which vals in traits are
initialized through a synthesized setter. These setters are
indistinguishable from normal setters at the IR level. Therefore, IR
emitted by scalac only emits mutable fields. This restriction might
not apply to other tools generating IR.

This commit allows the optimizer to optimize things based on the
immutability of a field.