Fix a bug on RecordRewriter when a variable is matched in many clauses, closes #1037