All BIT functions (BITOR, BITLSHIFT, ...) have a declared return type of Boolean, which is plain wrong since they return values. It has the odd side effect that a BIT function cannot have another BIT function as an argument. Everything seems to work if the return types for the BIT functions are changed to decimal.