Skip to content

Commit

Permalink
[checker][pattern-matching] Add nothing as a convenience factory fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
SamChou19815 committed Oct 28, 2023
1 parent 0bc5244 commit d7109fe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/samlang-core/src/checker/pattern_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractPatternNode>) -> Self {
Self(Rc::new(AbstractPatternNodeInner::Or(possibilities)))
}
Expand Down Expand Up @@ -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()],
Expand Down

0 comments on commit d7109fe

Please sign in to comment.