fix bugs in pattern matching compilation