This code is erroneously flagged as incompatible with chisel3. In fact, it is correct in both chisel2 and chisel3. D'oh.