mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
ensure Bit/Enum patterns are considered exhaustive
This commit is contained in:
parent
8a46765fee
commit
6e97734211
1 changed files with 29 additions and 3 deletions
|
@ -39,9 +39,35 @@ fn simplify<'a>(pattern: &crate::expr::Pattern<'a>) -> Pattern {
|
||||||
FloatLiteral(v) => Literal(Literal::Float(*v)),
|
FloatLiteral(v) => Literal(Literal::Float(*v)),
|
||||||
StrLiteral(v) => Literal(Literal::Str(v.clone())),
|
StrLiteral(v) => Literal(Literal::Str(v.clone())),
|
||||||
|
|
||||||
// TODO make sure these are exhaustive
|
// To make sure these are exhaustive, we have to "fake" a union here
|
||||||
BitLiteral(b) => Literal(Literal::Bit(*b)),
|
// TODO: use the hash or some other integer to discriminate between constructors
|
||||||
EnumLiteral { tag_id, .. } => Literal(Literal::Byte(*tag_id)),
|
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,
|
Underscore => Anything,
|
||||||
Identifier(_) => Anything,
|
Identifier(_) => Anything,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue