mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 16:51:53 +03:00
ensure Bit/Enum patterns are considered exhaustive
This commit is contained in:
parent
8a46765fee
commit
6e97734211
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user