ensure Bit/Enum patterns are considered exhaustive

This commit is contained in:
Folkert 2020-03-15 14:41:51 +01:00
parent 8a46765fee
commit 6e97734211

View File

@ -39,9 +39,35 @@ fn simplify<'a>(pattern: &crate::expr::Pattern<'a>) -> Pattern {
FloatLiteral(v) => Literal(Literal::Float(*v)),
StrLiteral(v) => Literal(Literal::Str(v.clone())),
// TODO make sure these are exhaustive
BitLiteral(b) => Literal(Literal::Bit(*b)),
EnumLiteral { tag_id, .. } => Literal(Literal::Byte(*tag_id)),
// To make sure these are exhaustive, we have to "fake" a union here
// TODO: use the hash or some other integer to discriminate between constructors
BitLiteral(b) => {
let union = Union {
alternatives: vec![
Ctor {
name: TagName::Global("False".into()),
arity: 0,
},
Ctor {
name: TagName::Global("True".into()),
arity: 0,
},
],
};
Ctor(union, TagName::Global(format!("{}", b).into()), vec![])
}
EnumLiteral { tag_id, enum_size } => {
let alternatives = (0..*enum_size)
.map(|id| Ctor {
name: TagName::Global(format!("{}", id).into()),
arity: 0,
})
.collect();
let union = Union { alternatives };
Ctor(union, TagName::Global(format!("{}", tag_id).into()), vec![])
}
Underscore => Anything,
Identifier(_) => Anything,