Repair and-pattern reading

This commit is contained in:
Tony Garnock-Jones 2021-09-11 02:53:46 +02:00
parent aabe7b2623
commit ef67347b8d
1 changed files with 7 additions and 0 deletions

View File

@ -111,8 +111,15 @@ pub fn gen_definition_reader(m: &mut ModuleContext, n: &str, d: &Definition) {
}
Definition::And { pattern_0, pattern_1, pattern_n } => {
let mut ps = vec![&**pattern_0, &**pattern_1];
let mut need_restore = false;
ps.extend(pattern_n);
ctxt.define_atom(&mut body, "_mark", item("r.mark()?"));
for e in &ps {
if need_restore {
body.push(item("r.restore(&_mark)?;"));
} else {
need_restore = true;
}
named_pattern_reader(&mut ctxt, e, None, &mut body);
}
construct(&ctxt, item(names::render_constructor(n)), true, &record_type(&ps), None, &mut body);