diff --git a/crates/samlang-core/src/checker/pattern_matching.rs b/crates/samlang-core/src/checker/pattern_matching.rs index bebbde90..99a65b08 100644 --- a/crates/samlang-core/src/checker/pattern_matching.rs +++ b/crates/samlang-core/src/checker/pattern_matching.rs @@ -50,6 +50,10 @@ impl AbstractPatternNode { })) } + pub(super) fn nothing() -> Self { + Self(Rc::new(AbstractPatternNodeInner::Or(Vec::with_capacity(0)))) + } + pub(super) fn or(possibilities: Vec) -> Self { Self(Rc::new(AbstractPatternNodeInner::Or(possibilities))) } @@ -405,6 +409,10 @@ mod tests { &[&[P::enum_(OPTION_NONE), P::wildcard()], &[P::wildcard(), P::enum_(OPTION_NONE)],], &[P::variant(OPTION_SOME, vec![P::wildcard()]), P::variant(OPTION_SOME, vec![P::wildcard()])] )); + assert!(!useful( + &[&[P::enum_(OPTION_NONE), P::wildcard()], &[P::wildcard(), P::enum_(OPTION_NONE)],], + &[P::nothing()] + )); assert!(!useful( &[ &[P::enum_(OPTION_NONE), P::wildcard()],