use tag id instead of name in exhaustiveness checking

This commit is contained in:
Folkert 2020-04-21 16:24:43 +02:00
parent 0b670baad4
commit f0aa598ff9
5 changed files with 89 additions and 40 deletions

View file

@ -136,9 +136,15 @@ fn pattern_to_doc<'b>(
Float(f) => alloc.text(f.to_string()),
Str(s) => alloc.string(s.into()),
},
Ctor(_, tag_name, args) => {
Ctor(union, tag_id, args) => {
let arg_docs = args.into_iter().map(|v| pattern_to_doc(alloc, v));
let tag = &union.alternatives[tag_id.0 as usize];
let tag_name = tag.name.clone();
// We assume the alternatives are sorted. If not, this assert will trigger
debug_assert!(tag_id == tag.tag_id);
let docs = std::iter::once(alloc.tag_name(tag_name)).chain(arg_docs);
alloc.intersperse(docs, alloc.space())